Built-in MD5, DSA, and RSA encryption. You need to introduce using system. Security. cryptography;
// 32-bit MD5 function public static string md532 (string Str) {string Cl = STR; string Pwd = ""; MD5 MD5 = md5.create (); byte [] S = md5.computehash (encoding. utf8.getbytes (CL); For (INT I = 0; I <S. length; I ++) {Pwd = PWD + s [I]. tostring ("X") ;}return PWD ;}// 16-bit MD5 function public static string md516 (string convertstring) {md5cryptoserviceprovider MD5 = new md5cryptoserviceprovider (); string t2 = bitconverter. tostring (md5.computehash (utf8encoding. default. getbytes (convertstring), 4, 8); t2 = t2.replace ("-", ""); t2 = t2.tolower (); Return T2 ;} public static string dsaencrypt (string Str) {byte [] bytes = encoding. ASCII. getbytes (STR); // select the signature method, including RSA and DSA dsacryptoserviceprovider dsac = new dsacryptoserviceprovider (); byte [] Sign = dsac. signdata (bytes); string strresult = convert. tostring (sign); Return strresult ;}
Des encryption
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. security. cryptography; using system. io; namespace deshelper {class desjob {public static string encryptkey = "oyea "; // define the key # region encrypted string /// <summary> /// encrypted string /// </Summary> /// <Param name = "str"> to encrypt string </param> // <returns> encrypted string </returns> Public static string encrypt (string Str) {descryptoserviceprovider descsp = new descryptoserviceprovider (); // instantiate the encryption/Decryption Class Object byte [] Key = encoding. unicode. getbytes (encryptkey); // defines the byte array to store the key byte [] DATA = encoding. unicode. getbytes (STR); // defines the byte array to store the string memorystream mstream = new memorystream (); // instantiate the memory stream object // use the memory stream to instantiate the encrypted Stream object cryptostream cstream = new cryptostream (mstream, descsp. createencryptor (key, key), cryptostreammode. write); cstream. write (data, 0, Data. length); // write data to the encrypted stream. flushfinalblock (); // release the encrypted stream return convert. tobase64string (mstream. toarray ()); // return the encrypted string} # endregion # region decryption string // <summary> // decrypt the string /// </Summary> // <Param name =" str "> the string to be decrypted </param> // <returns> the decrypted string </returns> Public static string decrypt (string Str) {descryptoserviceprovider descsp = new descryptoserviceprovider (); // instantiate the encryption/Decryption Class Object byte [] Key = encoding. unicode. getbytes (encryptkey); // defines the byte array to store the key byte [] DATA = convert. frombase64string (STR); // defines a byte array to store the string memorystream mstream = new memorystream (); // instantiate the memory stream object // use the memory stream to instantiate and decrypt the stream object cryptostream cstream = new cryptostream (mstream, descsp. createdecryptor (key, key), cryptostreammode. write); cstream. write (data, 0, Data. length); // write data into the decryption stream. flushfinalblock (); // release the decryption stream return encoding. unicode. getstring (mstream. toarray (); // returns the decrypted string} # endregion }}