'SM2 algorithm, the length of public key encryption is inconsistent with the expectation
The public key encrypts a 48Char data, and the result is arranged according to the format of C1C3C2.
C1
(randomly generating a point on the elliptic curve of SM2) and two BigInteger numbers of 32byte are generated, which is the first part of the SM2 encryption result, and 128Char is fixed.
C3
is the hash value, which is used to verify the data and is fixed at 64Char.
Now the fixed length(C1+C3) is 128+64=192Char.-
C2
is the real ciphertext, which is the encryption result of plaintext. Its length is 32Char, which is the same as that of plaintext.
So my encryption result should be 192+48=240Char.
Here is my calculation process.
public key:
d69625bdf33199474ea021ad261926683b2619acf15c1c285ff23b06e07bbddc78cf9361e971c2c43865397002830fd851f8d5d546e79b97d8479e6532f415d4
data:
egzjyuE5d4bts0yAVKRVfg==
24*2Char = 48Char
res:
04B415AED7CFD3E4A2857FD05AB54CD48993CBFB45B61BB192F1850BEBEA3F67B141DDD1FB986AD6EF246C02D1A7F8B018CC4236E221D51E2D68B91704CAB5CC16590127B9F1F3BBC72A856F3832A575F615FC0A4AE60F4D237B92F19EE30C6CA28A0F928DE7FE2D993829BF6CD5EDFFB2D994BFBE8E5114F5
I knew I needed to remove the starting 04, so the result became
res:
B415AED7CFD3E4A2857FD05AB54CD48993CBFB45B61BB192F1850BEBEA3F67B141DDD1FB986AD6EF246C02D1A7F8B018CC4236E221D51E2D68B91704CAB5CC16590127B9F1F3BBC72A856F3832A575F615FC0A4AE60F4D237B92F19EE30C6CA28A0F928DE7FE2D993829BF6CD5EDFFB2D994BFBE8E5114F5
Its length is 240
The partner gave me a reference result with a length of 224. I guess this length should be correct.
Here are their exact words.
Password plaintext 123456 Test data
Test environment public key:
d69625bdf33199474ea021ad261926683b2619acf15c1c285ff23b06e07bbddc78cf9361e971c2c43865397002830fd851f8d5d546e79b97d8479e6532f415d4
Random number encryption password plaintext:
egzjyuE5d4bts0yAVKRVfg==
Encrypted public key random number:
Here it is, with a length of 224.
5b00d62299e75c04c45a09303810b793787a2f2df1872253deee716b94a20fcaf64eb464ea322433ca48febca1f684ee5bf65ea1deb85b21b104ad6fbdc75a7bf1bb3a5cf75ab66cf1fe4ef ed3b6c0b512aaefc3bbb9132e65177233a77aaa93055c77334fdcd8a237b4faf15f8f0ae4
why??????
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
