91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-05-10
  • 語言: C/C++
  • 標簽: SM2??

資源簡介

采用該用例生成的SM2的公私鑰為字符串,非常方便SM2公私鑰密鑰對的導(dǎo)入導(dǎo)出,同時還寫了一個SM2加解密的算法,其中密鑰傳入都是以字符串的形式傳入的。

資源截圖

代碼片段和文件信息

#include?
#include?“openssl/err.h“
#include?
#include?
#include?
#include?
#include?
#include?
#include?

using?namespace?std;

EC_KEY*?CreateEC(unsigned?char*?key?int?is_public)
{
EC_KEY?*ec_key?=?NULL;
BIO?*keybio?=?NULL;
keybio?=?BIO_new_mem_buf(key?-1);
?
if?(keybio==NULL)?{
????????cout?< exit(1);
}
?
if(is_public)?{
ec_key?=?PEM_read_bio_EC_PUBKEY(keybio?NULL?NULL?NULL);
}
else?{
ec_key?=?PEM_read_bio_ECPrivateKey(keybio?NULL?NULL?NULL);
}
?
if(ec_key?==?NULL)?{
????????cout?< exit(1);
}
?
return?ec_key;
}

pair?GenKey(void)
{
????EC_KEY?*keypair?=?NULL;
????EC_GROUP?*group1?=?NULL;

????keypair?=?EC_KEY_new();
????if(!keypair)?{
????????cout?<????????exit(1);
????}

????group1?=?EC_GROUP_new_by_curve_name(NID_sm2p256v1);

????if(group1?==?NULL){
????????cout?<????????exit(1);
????}

????int?ret1?=?EC_KEY_set_group(keypair?group1);
????if(ret1?!=?1){
????????cout?<????????exit(1);
????}

????int?ret2?=?EC_KEY_generate_key(keypair);
????if(ret2?!=?1){
????????cout?<????????exit(1);
????}

????size_t?pri_len;
????size_t?pub_len;
????char?*pri_key?=?NULL;
????char?*pub_key?=?NULL;
?
BIO?*pri?=?BIO_new(BIO_s_mem());
BIO?*pub?=?BIO_new(BIO_s_mem());
?
PEM_write_bio_ECPrivateKey(pri?keypair?NULL?NULL?0?NULL?NULL);
PEM_write_bio_EC_PUBKEY(pub?keypair);
?
pri_len?=?BIO_pending(pri);
pub_len?=?BIO_pending(pub);
?
pri_key?=?new?char[pri_len?+?1];
pub_key?=?new?char[pub_len?+?1];
?
BIO_read(pri?pri_key?pri_len);
BIO_read(pub?pub_key?pub_len);

評論

共有 條評論