nodejs实现sm4加密解密字符串示例代码

代码语言:nodejs

所属分类:加密解密

代码描述:nodejs实现sm4加密解密字符串示例代码

代码标签: nodejs sm4 加密 解密 字符串 示例 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

const { SM4 } = require('gm-crypto')
const { SM2 } = require('gm-crypto')

const key = '0123456789abcdeffedcba9876543210' // Any string of 32 hexadecimal digits
const originalData = 'SM4 国标对称加密'

/**
 * Block cipher modes:
 * - ECB: electronic codebook
 * - CBC: cipher block chaining
 */

let encryptedData, decryptedData

// ECB
encryptedData = SM4.encrypt(originalData, key, {
  inputEncoding: 'utf8',
  outputEncoding: 'base64'
})
console.log(encryptedData);
decryptedData = SM4.decrypt(encryptedD.........完整代码请登录后点击上方下载按钮下载查看

网友评论0