Skip to content
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