跳转至

📦 OpenSSL

官网 | 下载 | 使用文档 | 开发文档

setup

linux

Bash
1
sudo apt-get install libssl-dev
  1. 下载 wget / 解压 tar -zxvf / 提权 chmod +x

  2. 配置安装选项 ./config shared --prefix=/opt/OpenSSL-x.y.z --openssldir=/opt/OpenSSL-x.y.z

  3. 安装 make && sudo make install

  4. 编写测试代码

    C
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    #include <stdio.h>
    #include <openssl/opensslv.h>
    #include <openssl/crypto.h>
    
    int main() {
        // 输出 OpenSSL 版本信息
        printf("OpenSSL version: %s\n", OpenSSL_version(OPENSSL_VERSION));
        printf("OpenSSL version number: %lx\n", OpenSSL_version_num());
        return 0;
    }
    

  5. 编译

    Bash
    1
    gcc a.c -I/.../openssl-x.y.z/include -L/.../openssl-x.y.z/lib64 -Wl,-rpath=/opt/openssl-x.y.z/lib64 -lssl -lcrypto
    

windows


use

生成密钥对

Bash
1
2
openssl genpkey -out pri.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2048
openssl pkey -in pri.pem -pubout -out pub.pem

dev