Aug 08, 2017 I have question about AES key and IV length. First of all, if, for example, I'm using drugs OpenSSL extension and opensslencrypt method, I can clearly see that key for 256-bit AES should be 32 bytes, and IV throws warning if it's different than 16 bytes. I can understand that, and everything is fine. However, in CryptoJS library the key and IV length is frustrating.
EncryptionEncryption is the process of converting the message to some other message so that only intended person can see the message. It involves a text that needs to be converted called as ciphertext and a key used to encrypt to message. The converted text is called as Encrypted Text. There is a number of algorithms out there for encryption. Based upon types of the key there are two types of Encryption.1.
Symmetric Encryption2. Asymmetric EncryptionSymmetric EncryptionIn this type of encryption, the same key is used to Encrypt and Decrypt the ciphertext.Asymmetric EncryptionIn this type of encryption, different keys are used to Encrypt and Decrypt the ciphertext.Encryption in JavascriptWe can use CryptoJS javascript library to encrypt and decrypt the ciphertext.First, Import the library, you either download the library or use CDN link. // Cipher Textvar cipherText = 'This Text will be Encrypted using AES';console.log('Cipher Text: '+ cipherText);var key = 'PasswordText';console.log('Key: '+ key);var encrptedText = CryptoJS.AES.encrypt(cipherText, key);console.log('Encrpted Text: '+ encrptedText.toString);DecryptionDecryption is the reverse of encryption i.e converting encrypted text to ciphertext. Luckily, CrptoJS also have functions to decrypt the encrypted text using the same key that was used to encrypt it.Decryption in JavascriptNow, We will illustrate an example to show the use of Decrypt function.