You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
665 B
32 lines
665 B
const CryptoJS = require('crypto-js'); |
|
|
|
const {encrypt, decrypt, A} = require('./static/sm4'); |
|
|
|
class Sm4Service { |
|
sm4Encrypt(data, key) { |
|
return encrypt(data, key); |
|
} |
|
|
|
sm4Decrypt(data, key) { |
|
return decrypt(data, key); |
|
} |
|
|
|
getKey() { |
|
return A(); |
|
} |
|
|
|
getSign(data, key) { |
|
var HmacSHA256 = CryptoJS.HmacSHA256(data, key) |
|
return CryptoJS.enc.Hex.stringify(HmacSHA256); |
|
} |
|
|
|
toHex(e) { |
|
for (var t = "", n = 0; n < e.length; n++) { |
|
"" === t ? t = e.charCodeAt(n).toString(16) : t += e.charCodeAt(n).toString(16); |
|
} |
|
return t |
|
} |
|
} |
|
|
|
|
|
module.exports = Sm4Service |