First, Introduction
1.aes encryption, in cryptography, also known as Rijndael encryption, is a block encryption standard used by the U.S. federal government. This standard, which replaces the original DES, has been analyzed and widely used worldwide. The Advanced Encryption Standard has become one of the most popular algorithms in symmetric key cryptography.
The 2.AES block length is fixed to 128 bits, and the key length can be 128,192 or 256 bits, while the key and block length used by Rijndael can be 32-bit integer multiples, with a 128-bit limit and 256-bit as the upper bound. including AES-ECB,AES-CBC,AES-CTR,AES-OFB,AES-CFB.
3. Here we only accept the usual ECB mode + pkcs7padding (same as the pkcs5padding value) to fill the encryption.
Second, the application
Use of AES in 1.nodejs
var crypto = require (' crypto ');
var Aesutil = Module.exports = {}; /** * AES Encryption * @param data to be encrypted content * @param key must be a 32-bit private key * @returns {string} */aesutil.encryption = function (data, key , iv) {IV = IV | |
"";
var clearencoding = ' UTF8 ';
var cipherencoding = ' base64 ';
var cipherchunks = [];
var cipher = Crypto.createcipheriv (' AES-256-ECB ', key, iv);
Cipher.setautopadding (TRUE);
Cipherchunks.push (cipher.update (data, clearencoding, cipherencoding));
Cipherchunks.push (Cipher.final (cipherencoding));
Return Cipherchunks.join ("); /** * AES Decryption * @param data to be decrypted content * @param key must be a 32-bit private key * @returns {string} */aesutil.decryption = function (data,
Key, IV) {if (!data) {return ""; } IV = IV | |
"";
var clearencoding = ' UTF8 ';
var cipherencoding = ' base64 ';
var cipherchunks = [];
var decipher = crypto.createdecipheriv (' AES-256-ECB ', key, iv);
Decipher.setautopadding (TRUE);
Cipherchunks.push (decipher.update (data, cipherencoding, clearencoding)); Cipherchunks.push (dEcipher.final (clearencoding));
Return Cipherchunks.join (");
}
Use of AES in 2.javascript
Download Third Party library crypto-js.js git address: https://github.com/brix/crypto-js
To introduce the crypto-js.js under SRC, encrypt the code as follows:
var key = "12345678" //Secret key must be: 8/16/32 bit
var message = "123456";
Encrypted
var encrypt = CryptoJS.AES.encrypt (message, CryptoJS.enc.Utf8.parse (key), {
Mode:CryptoJS.mode.ECB,
PADDING:CRYPTOJS.PAD.PKCS7
});
Console.log ("Value:" +encrypt);
Decrypt
var decrypt = CryptoJS.AES.decrypt (Encrypt, CryptoJS.enc.Utf8.parse (key), {
Mode:CryptoJS.mode.ECB,
PADDING:CRYPTOJS.PAD.PKCS7
});
Console.log ("Value:" +decrypt.tostring (CryptoJS.enc.Utf8));
The original author: Xian. Wang Lei
Original source: http://vipstone.cnblogs.com/
The above is the entire content of this article, I hope to help you learn.