JavaScript DES Encryption

Source: Internet
Author: User
Tags decrypt pkcs7 asp net

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

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.