Front end is encrypted with crypto.js

Source: Internet
Author: User
Tags pkcs7

I recently in the front-end use of cookies to save the password to the front-end to do encryption work, contact Crypto This JS, use is simple, here to record.

You can download the JS on this GitHub https://github.com/brix/crypto-js, it can introduce the required encryption method of JS, it can also introduce a crypto-js.js this file, it is equivalent to the introduction of all the encryption method, I am using the latter to introduce all the encrypted files at once, this file is not very large, but also acceptable.

Because my needs are password reversible, there is a certain degree of security, so using DES or AES, I am using AES, just on-line has a use of AES example, directly to use the

functionGetaesstring (DATA,KEY,IV) {//Encrypt    varKey =CryptoJS.enc.Utf8.parse (key); varIV =CryptoJS.enc.Utf8.parse (iv); varencrypted =CryptoJS.AES.encrypt (Data,key, {iv:iv, Mode:CryptoJS.mode.CBC, Padding:crypto    JS.PAD.PKCS7}); returnEncrypted.tostring ();//returns a ciphertext in the base64 format}functionGetdaesstring (ENCRYPTED,KEY,IV) {//decryption    varKey =CryptoJS.enc.Utf8.parse (key); varIV =CryptoJS.enc.Utf8.parse (iv); vardecrypted =CryptoJS.AES.decrypt (Encrypted,key, {iv:iv, Mode:CryptoJS.mode.CBC, Padding:c    RYPTOJS.PAD.PKCS7}); returndecrypted.tostring (CryptoJS.enc.Utf8); }functionGetaes (data) {//Encrypt    varKey = ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ';//secret key    varIV = ' 1234567812345678 '; varEncrypted =getaesstring (DATA,KEY,IV);//Ciphertext    varEncrypted1 =CryptoJS.enc.Utf8.parse (encrypted); returnencrypted;}functionGetdaes (data) {//decryption    varKey = ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ';//secret key    varIV = ' 1234567812345678 '; varDecryptedstr =getdaesstring (DATA,KEY,IV); returndecryptedstr;}

We can replace both key and IV, but we need to ensure that the encryption key and VI remain the same

Front end is encrypted with crypto.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.