html5 sha1,JavaScript 实现的base64加密、md5加密、sha1加密及AES加密

1. Base64加密2). 安装npm install --save js-base643). 使用

2. MD5加密2). 安装npm install js-md53). 使用

3. sha1加密2). 安装npm install js-sha13). 使用

4. 自定义加解密

5. AES加密2). 安装npm install aes-js3). 使用

CBC - Cipher-Block Chaining (recommended)// An example 128-bit keyvar key = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; // The initialization vector (must be 16 bytes)var iv = [ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,35, 36 ]; // 加密// Convert text to bytes (text must be a multiple of 16 bytes)var text = 'TextMustBe16Byte';var textBytes = aesjs.utils.utf8.toBytes(text); var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);var encryptedBytes = aesCbc.encrypt(textBytes); // To print or store the binary data, you may convert it to hexvar encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);console.log(encryptedHex);// "104fb073f9a131f2cab49184bb864ca2" // 解密// When ready to decrypt the hex string, convert it back to bytesvar encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex); // The cipher-block chaining mode of operation maintains internal// state, so to decrypt a new instance must be instantiated.var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);var decryptedBytes = aesCbc.decrypt(encryptedBytes); // Convert our bytes back into textvar decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);console.log(decryptedText);// "TextMustBe16Byte"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值