OpenSSL:已如何初始化公钥加密密钥? [英] openSSL: how to initialize keys for public key encryption?
本文介绍了OpenSSL:已如何初始化公钥加密密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有关使用OpenSSL API进行公钥加密,如何是关键(公众&安培;民营)在C程序初始化,鉴于* .key文件格式的私钥,并在* .pem文件格式的公钥:
For using openSSL API for public key encryption, how is the key (public & private) initialized in a C program, given private key in *.key file format, and public key in *.pem file format:
EVP_PKEY *key;
/* How is key initialized ?
*/
ctx = EVP_PKEY_CTX_new(key);
感谢。
推荐答案
试试这个:
EVP_PKEY *pkey;
FILE *f = fopen("<path for your PEM or DER encoded key>", "rb");
if (f == NULL){
// error handling...
}
//if your key is PEM encoded use this
pkey = PEM_read_PUBKEY(f, NULL, NULL, NULL); // pkey now contains the pubKey.
//We are passing NULL to the others parameters because we dont need password to read a public key
//if your key is DER encoded use this
pkey = d2i_PUBKEY_fp(f, NULL);
if (pkey == NULL){
// error handling...
}
我没有测试,但应该工作。
I didnt test but should work.
这篇关于OpenSSL:已如何初始化公钥加密密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文