/// <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 (){}}