- 論壇徽章:
- 0
|
RSA *rsa=NULL;
printf("正在產(chǎn)生RSA密鑰...");
rsa = RSA_generate_key(1024, RSA_F4, NULL, NULL);
if(rsa==NULL)
{
printf("gen rsa error\n");
return false;
}
// 公鑰
BIO *bp = BIO_new(BIO_s_file());
if(BIO_write_filename(bp, "c:\\public.pem")<=0)
{
printf("write error\n");
return false;
}
if(PEM_write_bio_RSAPublicKey(bp, rsa)!=1)
{
printf("write public key error\n");
return false;
}
BIO_free_all(bp);
char passwd[]="1234";
// 私鑰
bp = BIO_new_file("c:\\private.pem", "w+");
if(PEM_write_bio_RSAPrivateKey(bp, rsa, EVP_des_ede3(), (unsigned char*)passwd, 4, NULL, NULL)!=1)
{
printf("write public key error\n");
return false;
}
BIO_free_all(bp);
--------------------
經(jīng)過測試應(yīng)該是可以的 |
|