npm install sm-crypto --save
const sm4 = require('sm-crypto').sm4; let sm4Api = { encrypt: function (data) { if(!data) return data; return this.convertToBase64(sm4.encrypt(data, "43484c43484c40323032332121212121")); }, decrypt: function (data) { if(!data) return data; return sm4.decrypt(this.convertToHex(data), "43484c43484c40323032332121212121"); }, convertToBase64: function(hexString) { const buffer = Buffer.from(hexString, 'hex'); const base64String = buffer.toString('base64'); return base64String; }, convertToHex: function(base64String) { const buffer = Buffer.from(base64String, 'base64'); const hexString = buffer.toString('hex'); return hexString; } }; export default sm4Api;
SM4加密、解密
最新推荐文章于 2024-09-06 22:35:40 发布