You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3.1.1 version encrypt text by SM2.The length of the ciphertext it too long.I look up information.The ciphertext is found in ASN.1 format.
I have no idea how to code.
Generate the EVP_Pkey through HEX:
*ctx = EVP_PKEY_CTX_new_from_name(nullptr, "SM2", nullptr);
int i = EVP_PKEY_fromdata_init(*ctx); if (i != 1) break;
params_build = OSSL_PARAM_BLD_new();
OSSL_PARAM_BLD_push_utf8_string(params_build, OSSL_PKEY_PARAM_GROUP_NAME, "SM2", 0);
if (pubKeyLen > 0) {
OSSL_PARAM_BLD_push_octet_string(params_build, OSSL_PKEY_PARAM_PUB_KEY, publicKeyXY.data(), publicKeyXY.size());
}
if (priKeyLen > 0) {
OSSL_PARAM_BLD_push_BN(params_build, OSSL_PKEY_PARAM_PRIV_KEY, BNPriKey);
}
params = OSSL_PARAM_BLD_to_param(params_build);
int status = EVP_PKEY_fromdata(*ctx, evpPkey, EVP_PKEY_KEYPAIR, params);
encrypt code:
evpPkeyCTX = EVP_PKEY_CTX_new_from_pkey(nullptr, evpPkey, nullptr); if (evpPkeyCTX == nullptr) break;
size_t dataLen;
if (cryptType == 0) {
i = EVP_PKEY_encrypt_init(evpPkeyCTX); if (1 <= 0) break;
i = EVP_PKEY_encrypt(evpPkeyCTX, nullptr, &dataLen, (unsigned char*)strData.data(), strData.length()); if (i <= 0) break;
dataBuf = (unsigned char*)OPENSSL_zalloc(dataLen); if (dataBuf == nullptr) break;
i = EVP_PKEY_encrypt(evpPkeyCTX, dataBuf, &dataLen, (unsigned char*)strData.data(), strData.length()); if (i <= 0) break;
}
else {
i = EVP_PKEY_decrypt_init(evpPkeyCTX); if (1 <= 0) break;
i = EVP_PKEY_decrypt(evpPkeyCTX, nullptr, &dataLen, (unsigned char*)strData.data(), strData.length()); if (i <= 0) break;
dataBuf = (unsigned char*)OPENSSL_zalloc(dataLen); if (dataBuf == nullptr) break;
i = EVP_PKEY_decrypt(evpPkeyCTX, dataBuf, &dataLen, (unsigned char*)strData.data(), strData.length()); if (i <= 0) break;
}
retStr.assign((char*)dataBuf, dataLen);
priKey hex: D07E969F55F8D8D1F813A0EF0237CF93E53679A3CB65FD42FD9EB3239DBE5BF5
pubKey hex: A40C45E02417662AF9DA9EEC5953E8604FB2D59BC3EAE5AABE1D7540B588941E6484EEC9DDCF46B84D198E6659770484A38CCC0646A7546FE5AB2E3D5CD2CF03
original text:123 0x495051
ciphertext,the length is 111 306D022100D6745DA3D9DFFA524C28F604044BF72F001DFCA7201B5F25F5A65E8A37E7E403022100B18DD514D804A523E1DC43BCF3E1EAB8F464B7DC3466144A86AEACCF0EEE420B04209CD81FF4E9AD4BEBB5C69FB62ECE71272E3E375706488C6886CE0434C82DF87B040329106B
I use the online SM2 tool,use the same pubkey,the length of ciphertext is 99: 6F2FC4248432255EDD9641D45D6753C7F27A914BB91303D6A08D34C5F9CDD6934205A86FFDE49B1C9D7AF58C57A96CC0963C3E671F37A4A49CD7894875B9987F942FE2EF8F25686329C92047D3CB674E37760B03BB647F0D67972D0B05AC0DCFA7167A
This discussion was converted from issue #21488 on July 19, 2023 03:37.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
3.1.1 version encrypt text by SM2.The length of the ciphertext it too long.I look up information.The ciphertext is found in ASN.1 format.
I have no idea how to code.
Generate the EVP_Pkey through HEX:
encrypt code:
priKey hex:
D07E969F55F8D8D1F813A0EF0237CF93E53679A3CB65FD42FD9EB3239DBE5BF5
pubKey hex:
A40C45E02417662AF9DA9EEC5953E8604FB2D59BC3EAE5AABE1D7540B588941E6484EEC9DDCF46B84D198E6659770484A38CCC0646A7546FE5AB2E3D5CD2CF03
original text:123
0x495051
ciphertext,the length is 111
306D022100D6745DA3D9DFFA524C28F604044BF72F001DFCA7201B5F25F5A65E8A37E7E403022100B18DD514D804A523E1DC43BCF3E1EAB8F464B7DC3466144A86AEACCF0EEE420B04209CD81FF4E9AD4BEBB5C69FB62ECE71272E3E375706488C6886CE0434C82DF87B040329106B
I use the online SM2 tool,use the same pubkey,the length of ciphertext is 99:
6F2FC4248432255EDD9641D45D6753C7F27A914BB91303D6A08D34C5F9CDD6934205A86FFDE49B1C9D7AF58C57A96CC0963C3E671F37A4A49CD7894875B9987F942FE2EF8F25686329C92047D3CB674E37760B03BB647F0D67972D0B05AC0DCFA7167A
Beta Was this translation helpful? Give feedback.
All reactions