1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > html5 sha1 JavaScript 实现的base64加密 md5加密 sha1加密及AES加密

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

时间:2021-06-17 14:22:04

相关推荐

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"

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。