|
楼主 |
发表于 2024-7-5 14:31:24
|
显示全部楼层
广东省东莞市
解密部分JS代码:
function doDecrypt(encryptData, privateKey, cipherMode = 1, {
output = 'string',
} = {}) {
privateKey = new BigInteger(privateKey, 16)
let c3 = encryptData.substr(128, 64)
let c2 = encryptData.substr(128 + 64)
if (cipherMode === C1C2C3) {
c3 = encryptData.substr(encryptData.length - 64)
c2 = encryptData.substr(128, encryptData.length - 128 - 64)
}
const msg = _.hexToArray(c2)
const c1 = _.getGlobalCurve().decodePointHex('04' + encryptData.substr(0, 128))
const p = c1.multiply(privateKey)
const x2 = _.hexToArray(_.leftPad(p.getX().toBigInteger().toRadix(16), 64))
const y2 = _.hexToArray(_.leftPad(p.getY().toBigInteger().toRadix(16), 64))
let ct = 1
let offset = 0
let t = [] // 256 位
const z = [].concat(x2, y2)
const nextT = () => {
// (1) Hai = hash(z || ct)
// (2) ct++
t = sm3([...z, ct >> 24 & 0x00ff, ct >> 16 & 0x00ff, ct >> 8 & 0x00ff, ct & 0x00ff])
ct++
offset = 0
}
nextT() // 先生成 Ha1
for (let i = 0, len = msg.length; i < len; i++) {
// t = Ha1 || Ha2 || Ha3 || Ha4
if (offset === t.length) nextT()
// c2 = msg ^ t
msg[i] ^= t[offset++] & 0xff
}
// c3 = hash(x2 || msg || y2)
const checkC3 = _.arrayToHex(sm3([].concat(x2, msg, y2)))
if (checkC3 === c3.toLowerCase()) {
return output === 'array' ? msg : _.arrayToUtf8(msg)
} else {
return output === 'array' ? [] : ''
}
} |
|