Recently done web data encryption work, using Cryptojs v3.1.2 this JavaScript script, online comparison of the quality of the article is too little, verified that the results of encryption and ASP Net DES encryption results consistent
Reference articles
https://gist.github.com/ufologist/5581486
Cryptojs v3.1.2
Https://code.google.com/p/crypto-js/downloads/list
Examples are as follows
<HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <title>JS set des encryption processing</title> <Scripttype= "Text/javascript"src= "Js/jquery.min.js"></Script> <Scriptsrc= "Js/rollups/tripledes.js"></Script> <Scriptsrc= "Js/components/mode-ecb.js"></Script> <Script> //DES Decryption Encryption functionencryptbydes (message, key) {varKeyhex=CryptoJS.enc.Utf8.parse (key); varEncrypted=CryptoJS.DES.encrypt (Message, Keyhex, {Mode:CryptoJS.mode.ECB, Paddin G:CRYPTOJS.PAD.PKCS7}); returnencrypted.tostring (); } //DES Decryption functiondecryptbydes (ciphertext, key) {varKeyhex=CryptoJS.enc.Utf8.parse (key); //Direct Decrypt Ciphertext vardecrypted=CryptoJS.DES.decrypt ({ciphertext:CryptoJS.enc.Base64.parse (ciphertext)}, Keyhex, {Mode:CryptoJS.mode.ECB, padding:CryptoJS.pad.Pkcs7}); returndecrypted.tostring (CryptoJS.enc.Utf8); } </Script> <Script> //Encrypt functionEncryptstr () {varstrkey=$.trim ($ ('#key'). Val ()); varSTRMSG=$.trim ($ ('#text1'). Val ()); $('#text2'). Val (Encryptbydes (STRMSG, strkey)); } //decryption functionDecryptstr () {varstrkey=$.trim ($ ('#key'). Val ()); varCiphertext=$.trim ($ ('#text2'). Val ()); $('#text3'). Val (Decryptbydes (ciphertext, strkey)); } </Script> </Head> <Body> <H1>JS set des encryption processing</H1> <label>Key</label> <inputtype= "text"value= ' 12345678 'ID= "Key" /> <Div> <textareaID= "Text1"placeholder= "Please enter characters that need to be encrypted">abcde12345 this Chinese [email protected]#[email protected]$#%$#^% (":") []=_-</textarea> <inputtype= "button"value= "Encrypted"onclick= "encryptstr ();" /> <textareaID= "Text2"></textarea> <inputtype= "button"value= "Decryption"onclick= "decryptstr ();" /> <textareaID= "Text3"></textarea> </Div> </Body></HTML>
JavaScript DES Encryption