Encryption...

Source: Internet
Author: User
/// <Summary> /// encrypted character /// </Summary> /// <Param name = ptoencrypt> encrypted string </param> /// <Param name = skey> encryption key </param> // <returns> return encryption </returns> publicclass descmd5 {publicstaticstring skey = "abcdefgh "; publicstring skey {get {return skey;} set {skey = value ;}} /// <summary> /// encryption function /// </Summary> /// <Param name = "ptoencrypt"> </param> /// <returns> </returns> publicstring encrypt (string ptoencrypt) {// descryptoserviceprovider des = new descryptoserviceprovider (); des. key = system. text. asciiencoding. ASCII. getbytes (skey); // establishes the key and offset des of the encryption object. IV = asciiencoding. ASCII. getbytes (skey); // use asciiencoding in the original text. the getbytes method of the ASCII method byte [] inputbytearray = encoding. default. getbytes (ptoencrypt); // put the string in the byte array memorystream MS = new memorystream (); // create a stream cryptostream cs = new cryptostream (MS, des. createencryptor (), cryptostreammode. write); CS. write (inputbytearray, 0, inputbytearray. length); CS. flushfinalblock (); // The encrypted result is put in the memory to stringbuilder ret = new stringbuilder (); foreach (byte B in ms. toarray () {ret. appendformat ("{0: X2}", B);} return ret. tostring ();} /// <summary> // decrypt the ESC function // </Summary> /// <Param name = "ptodecrypt"> decrypted string </param> // /<Param name = "skey"> key (only eight-byte key is supported, same as the preceding encryption key) </param> // <returns> returns the decrypted string </returns> publicstring decrypt (string ptodecrypt) {descryptoserviceprovider des = new descryptoserviceprovider (); byte [] inputbytearray = newbyte [ptodecrypt. length/2]; for (INT I = 0; I <ptodecrypt. length/2; I ++) {int x = convert. toint32 (ptodecrypt. substring (I * 2, 2), 16); inputbytearray [I] = (byte) x;} des. key = asciiencoding. ASCII. getbytes (skey); des. IV = asciiencoding. ASCII. getbytes (skey); memorystream MS = new memorystream (); cryptostream cs = new cryptostream (MS, Des. createdecryptor (), cryptostreammode. write); CS. write (inputbytearray, 0, inputbytearray. length); CS. flushfinalblock (); return system. text. encoding. default. getstring (Ms. toarray ();} public descmd5 (){}}

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.