C # A packaged encryption decryption class

xiaoxiao2021-03-06  41

using System; using System.Text; using System.Globalization; using System.Security.Cryptography; using System.Windows.Forms; namespace Jh.Encrypts {public class JhEncrypt {///

/// /// constructor public jhencrypt () {} /// /// Using the default key string encryption /// /// Ming Text /// Ciphertext public static string encrypt (String Original) {Return Encrypt (Original, "Jasonheung");} /// /// Using the default key decryption ///// /// Ciphertext /// 明文 public static string decrypt (string original) {Return Decrypt (Original, "Jasonheung", System.text.Encoding.default);} /// /// Use a given key to decrypt /// /// Ciphertext / // Key /// clear text public static string decrypt (string original, string key) {Return Decrypt (Original, Key, System.Text. Encoding.default);} /// /// Use the default key to decrypt, return to the specified encoding method clear text /// /// Ciphertext /// encoding method /// Public Static String Decrypt (String Original, Encoding Encoding) {Return Decrypt (Original, "Jasonheung", Encoding;} /// /// Use a given key encryption //// / // Original text /// Key ///

Character encoding scheme /// ciphertext public static string encrypt (string original, string key) {byte [] buff = system.text.encoding.default.getbytes (Original); byte [] KB = system.text.encoding.default.getbytes (key); Return Convert.TOBASE64STRING (Encrypt (BUFF, KB));} ///

/// Use a given key to decrypt /// < / summary> /// ciphertext /// Key /// character encoding embodiment /// plain public static string Decrypt (string encrypted, string key, encoding encoding) {byte [] buff = Convert.FromBase64String (encrypted); byte [] kb = System. Text.Encoding.default.getbytes (key); return encoding.getstring (Decrypt (BUFF, KB));} /// /// Generate MD5 summary /// /// data source /// summary public static byte [] MakeMD5 (byte [] original) {MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider (); byte [] keyhash = Hashmd5.computehash (ORIGINAL); Hashmd5 = NULL; RETURN Keyhash;} /// /// Using a given key encrypted //// /// clear text < / param> /// Key /// Ciphertext public static bottypt (byte [] original, Byte [] key) { TripleDescryptoserviceProvider DES = New TripEDescryptoToServiceProvider (); des.key = makemd5 (key); des.mode = ciphermode.ecb;

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

New Post(0)