JS front-end data encryption plug-in

Source: Internet
Author: User
Tags decrypt hmac sha1 asymmetric encryption

(2014-11-14 15:37:35) reproduced
Tags: it Category: Web front-end development


Most dynamic Web sites support the transfer of data from the client to the server, which is dangerous if the data being passed is intercepted by others, especially some user name passwords. This is when we need to encrypt the data before passing the data. Now there are many encryption algorithms, for example: Md5,sha-1,sha-256,aes,rabbit,marc4,hmac and so on. Share several front-end encryption plugins below.

  1. Braintree.js
    It is designed to be used with the client's library. The cryptographic library submits data (usually on a mobile device or merchant-hosted Web site via a form) and encrypts the public key using an asymmetric key pair. On the server, use the client to send the public key of the encryption number.
    1 var clientsideencryptionkey = "Your_encryption_key"; 2 var braintree = Braintree.create (Clientsideencryptionkey); 3 $ (# Transaction_form). Submit (Function () {4     Encryptedform (). submit (); 5     return false;6});

  2. burningpig-encryption
    Encrypting using the RSA algorithm
    1 var RSA = require ("./src/rsa.js"); 2 var key = new RSA. Key (); 3? 4 var message = "All your bases is belong to us."; 5 Console.log ("message:\n" +message+ "\ n"); 6  7//Generate a key 8 key.generate (1024x768, "10001"), 9 Console.log ("key:\n"), Console.log ("N:" + key.n.tostring (16)) ; Console.log ("E:" + key.e.tostring), Console.log ("D:" + key.d.tostring), Console.log ("\ n"); 14 15// Encrypt16 var encrypted = key.encrypt (message), Console.log ("encrypted:\n" + rsa.linebrk (encrypted, +) + "\ n"); 18 19/ /Decrypt20 var decrypted = Key.decrypt (encrypted), Console.log ("decrypted:" + rsa.linebrk (decrypted, +) + "\ n"); 22 23  var sig = key.signstring (Message, "sha256"), Console.log ("String signature: \ n" + rsa.linebrk (SIG, +)); + Var PubKey = new RSA. Key (), PUBKEY.N = key.n;28 pubkey.e = key.e;29 var verified = pubkey.verifystring (message, SIG), Console.log ("Ve Rfied: "+ verified);

  3. This plug-in is used in the
  4. MD5
     1//Quick Test 2 var input1 = "ABC"; 3 var input2 = ["A", "B", "C"]; 4 var input3 = [0x41, 0x42, 0x43]; 5 alert (f Aultylabs. MD5 (INPUT1) = = "902fbdd2b1df0c4f70b4a5d23525e932"); 6 Alert (Faultylabs. MD5 (input2) = = "902fbdd2b1df0c4f70b4a5d23525e932"); 7 Alert (Faultylabs. MD5 (INPUT3) = = "902fbdd2b1df0c4f70b4a5d23525e932"); 8 9//ArrayBuffer10 var abuf = new ArrayBuffer (3) one var vu8 = new Uint8array (abuf) vu8[0] = 0x41; VU8[1] = 0x42; VU8[2] = 0x4313 alert (faultylabs. MD5 (abuf) = = "902fbdd2b1df0c4f70b4a5d23525e932")/Typed Array uint32array16 var au32 = new Uint32array (1) au32[ 0] = 0xDDCCBBAA alert (faultylabs. MD5 (au32) = = "ca6ffbf95b47864fd4e73f2601326304") 


  5. Crypto.js
    is a comprehensive library that contains many algorithms, MD5,SHA-1,SHA-256,AES,RABBIT,MARC4,HMAC,HMAC-MD5,HMAC-SHA1,HMAC-SHA256,PBKDF2
    1 var Cryptojs = require ("Crypto-js"); 2 Console.log (CRYPTOJS.HMACSHA1 ("Message", "Key");

  6. Sjcl
    1 sjcl.encrypt ("password", "Data") 2 Sjcl.decrypt ("Password", "Encrypted-data")

  7. Jcryption
    ? Under normal circumstances, when data is submitted, if no SSL data is sent using plain text. Jcryption This jquery plugin is capable of encrypting post/get data submitted by forms. Jcryption uses the RSA public key cryptography algorithm to encrypt, and the project also provides a PHP file to handle the decryption of the data.
    1 $ (function () {2     $ ("form"). Jcryption (); 3});

  8. Jshashes
    Jshashes is an extended hashing algorithm implemented by pure JavaScript. Its goal is to provide a standalone, fast, and simple hashing algorithm solution for both the client and server side of the JavaScript environment. Include algorithm: md5,sha-1,sha-256,sha-512,hmac,ripemd-160
    1//New MD5 instance 2 var MD5 = new Hashes.md5; 3//New SHA1 instance 4 var SHA1 = new Hashes.sha1;  5//New SHA256 instance 6 var SHA256 =  new hashes.sha256; 7//New SHA512 Instace 8 var SHA512 = new hashes.sha512; 9 New RIPEMD-160 instace10 var RMD160 = new HASHES.RMD160;11//sample string12 var str = ' sample text! '; //Output to Console14 console.log (' MD5: ' + md5.hex (str)), Console.log (' SHA1: ' + sha1.hex (str)), Console.log (' SHA : ' + sha256.hex (str)], Console.log (' SHA512: ' + sha512.hex (str)), Console.log (' RIPEMD-160: ' + rmd160.hex (str));


There are a lot of data encryption on the Internet, most of the idea is to use asymmetric encryption method, if you have a good way to communicate more.

Also attached are two plugins encrypted and decrypted in the node. JS Environment:



JS front-end data encryption plug-in

Related Article

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.