windows平台RSA密钥生成

1、安装openssl工具

下载安装openssl工具,执行安装目录bin下的"openssl.exe",执行后会弹出命令窗口。

2、生成私钥

在命令窗口输入“genrsa -out rsa_private_key.pem 1024”命令,回车执行,成功后bin目录下会多出一个rsa_private_key.pem文件,如下:

3、生成公钥

同上,继续在命令窗口输入"rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem"命令,回车执行,成功后bin目录下又会多出一个rsa_public_key.pem文件。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个示例程序,可以在Windows下使用C语言调用openssl库生成RSA密钥对: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/rsa.h> #include <openssl/pem.h> int main() { int ret = 0; RSA *rsa = NULL; BIGNUM *e = NULL; BIO *bio_pub = NULL, *bio_pri = NULL; char *pub_key = NULL, *pri_key = NULL; // 生成RSA密钥对 e = BN_new(); ret = BN_set_word(e, RSA_F4); if (ret != 1) { printf("BN_set_word failed\n"); return -1; } rsa = RSA_new(); ret = RSA_generate_key_ex(rsa, 2048, e, NULL); if (ret != 1) { printf("RSA_generate_key_ex failed\n"); return -1; } // 生成公钥和私钥 bio_pub = BIO_new(BIO_s_mem()); ret = PEM_write_bio_RSAPublicKey(bio_pub, rsa); if (ret != 1) { printf("PEM_write_bio_RSAPublicKey failed\n"); return -1; } bio_pri = BIO_new(BIO_s_mem()); ret = PEM_write_bio_RSAPrivateKey(bio_pri, rsa, NULL, NULL, 0, NULL, NULL); if (ret != 1) { printf("PEM_write_bio_RSAPrivateKey failed\n"); return -1; } // 从BIO中读取公钥和私钥 long pub_len = BIO_get_mem_data(bio_pub, &pub_key); long pri_len = BIO_get_mem_data(bio_pri, &pri_key); if (pub_len <= 0 || pri_len <= 0) { printf("BIO_get_mem_data failed\n"); return -1; } // 输出公钥和私钥 printf("public key:\n%s\n", pub_key); printf("private key:\n%s\n", pri_key); // 释放资源 RSA_free(rsa); BN_free(e); BIO_free_all(bio_pub); BIO_free_all(bio_pri); free(pub_key); free(pri_key); return 0; } ``` 这个程序使用了openssl库中的RSA函数和PEM函数,生成了一个2048位的RSA密钥对,并且输出了公钥和私钥。需要注意的是,这个程序中的公钥和私钥都是以PEM格式保存的,如果需要使用其他格式,可以使用openssl库中的其他函数进行处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值