Skip to content

fix C1(uncompressed public key)format for sm2 standard #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sm2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function doDecrypt(encryptData, privateKey, cipherMode = 1) {

privateKey = new BigInteger(privateKey, 16)

if (encryptData.substr(0, 2) === '04') {
encryptData = encryptData.substring(2)
}

const c1X = encryptData.substr(0, 64)
const c1Y = encryptData.substr(0 + c1X.length, 64)
const c1Length = c1X.length + c1Y.length
Expand Down
7 changes: 1 addition & 6 deletions src/sm2/sm2.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@ class SM2Cipher {
initEncipher(userKey) {
const keypair = _.generateKeyPairHex()
const k = new BigInteger(keypair.privateKey, 16)
let publicKey = keypair.publicKey

this.p2 = userKey.multiply(k) // [k](Pb)
this.reset()

if (publicKey.length > 128) {
publicKey = publicKey.substr(publicKey.length - 128)
}

return publicKey
return keypair.publicKey
}

encryptBlock(data) {
Expand Down