GmSSL icon indicating copy to clipboard operation
GmSSL copied to clipboard

SM2_do_decrypt 解密报错 各路大神帮忙看看 什么原因导致

Open bylively opened this issue 8 years ago • 2 comments

int sm2_decrypt(EVP_PKEY *PriKey, const unsigned char *msg, unsigned int inlen, unsigned char *out, unsigned int *outlen) { int ret = 0; int i; //EC_KEY *pub_key = NULL; EC_KEY *pri_key = NULL; SM2CiphertextValue *cv = NULL; const EVP_MD *md = EVP_sm3(); pri_key = PriKey->pkey.ec;

unsigned char * temp = (unsigned char *)malloc(128);
temp[0] = 0x04;
memcpy(temp+1, msg, 112);

printf("temp:\n");
for(i = 0; i < 113; i++)
{
	printf("%02x ",temp[i]);
	if(0 == (i+1)%32)
	printf("\n");
}
printf("\n");
const EC_GROUP *group = EC_KEY_get0_group(pri_key);
if(NULL == group)
{
	log("EC_KEY_get0_group failed\n");
	goto end;
}
cv = o2i_SM2CiphertextValue(group, md,  NULL, (const unsigned char **)&temp, 113);
if(NULL == cv)
{
	log("o2i_SM2CiphertextValue failed\n");
	goto end;
}
if (!SM2_do_decrypt(md, cv, out, outlen, pri_key)) {
	log("SM2_do_decrypt failed\n");
	goto end;
}

ret = 1;

end: ERR_print_errors_fp(stderr); EC_KEY_free(pri_key); SM2CiphertextValue_free(cv); free(temp); temp = NULL; return ret; }

运行结果: temp: 04 67 68 9e 62 67 e4 16 b5 69 e4 3a 51 68 19 15 66 d3 5f 74 c9 ff 3b 64 e5 f4 70 5f 6a 9a f9 af f8 3b 15 7a 94 1f d6 ec a8 da 73 d8 ea 13 da 79 cc ed 74 f2 1f 1b 9f 2a 23 3f 70 24 35 76 a2 c1 df 82 40 a1 26 13 a8 5f dc 59 34 87 5a c6 9d 5c e3 de 17 68 ac a8 d1 f4 82 2a d0 24 92 e5 73 88 ff ab 67 b6 16 ea ad c1 06 64 54 d6 c0 ac fc 14 fa 3085302688:error:42065067:BASE58 routines:SM2_do_decrypt:invalid ciphertext:crypto/sm2/sm2_enc.c:346:

请大神帮看看什么原因导致的 谢谢

bylively avatar Jul 02 '18 02:07 bylively

我也碰到invalid ciphertext的报错,后来你解决没有?

hustms avatar Mar 03 '19 07:03 hustms

Marked as stale issue. Will be closed later if no activity for a while.

github-actions[bot] avatar Oct 04 '20 01:10 github-actions[bot]