Cryptography

zhaozj2021-02-16  93

Using system.sem.text; using system.security.cryptography; using system.io; Namespace des1 {////

/// Testdea's summary description. /// public class des3 {public des3 () {}

///

/// encryption method /// /// plaintext, Unicode encoding /// password, base64 encoding /// encryption result, base64 encoding public static string encrypt (string strData, string bs64key) {TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider ();

des.Mode = CipherMode.ECB; des.Padding = PaddingMode.PKCS7; des.Key = Convert.FromBase64String (bs64key); byte [] bData = ASCIIEncoding.ASCII.GetBytes (strData); return Convert.ToBase64String (des.CreateEncryptor ( ) .Transformfinalblock (bdata, 0, bdata.length);}

///

///////// /// plaintext, base64 encoding /// password, base64 encoding /// decrypting result, Unicode encoding public static string decrypt (string strData, string bs64key) {TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider (); des.Mode = CipherMode.ECB; des .Padding = PaddingMode.PKCS7; des.Key = Convert.FromBase64String (bs64key); byte [] bData = Convert.FromBase64String (strData);. return ASCIIEncoding.ASCII.GetString (des.CreateDecryptor () TransformFinalBlock (bData, 0, bData }}}

转载请注明原文地址:https://www.9cbs.com/read-15332.html

New Post(0)