C # implements an instance of Base64-based cryptographic decryption class

Source: Internet
Author: User
Tags decrypt key string

The example in this article describes the C # implementation of BASE64-based cryptographic decryption classes. Share to everyone for your reference. Specific as follows:

This C # class is a Base64 based encryption and decryption class, users can use the default key to encrypt, decrypt, or can set their own keys for encryption and decryption, very useful

Using system;using system.security.cryptography;using system.text;namespace dotnet.utilities{//<summary>// A summary description of the Encrypt.   </summary> public class Dencrypt {///<summary>//Construction method///</summary> public Dencrypt () {} #region Use the default key string to encrypt/decrypt string////<summary>/////Use the default key string to encrypt the string///</summary>//<param name= "or Iginal "> PlainText </param>//<returns> redaction </returns> public static string Encrypt (string original) {RET  Urn Encrypt (original, "sharejs.com"); }///<summary>///decrypt string with default key string///</summary>//<param name= "original" > Redaction </param>// /<returns> plaintext </returns> public static string Decrypt (string original) {return Decrypt (original, "sharejs.c  Om ", System.Text.Encoding.Default); #endregion #region Encrypt/decrypt string using the given key string///<summary>///////////////<p Aram Name= "original" > Original text </param>//<param NamE= "key" > Key </param>//<param name= "encoding" > character encoding scheme </param>//<returns> redaction </returns > public static string Encrypt (string original, string key) {byte[] buff = System.Text.Encoding.Default.GetBytes (o   riginal);   Byte[] KB = System.Text.Encoding.Default.GetBytes (key);  Return convert.tobase64string (Encrypt (BUFF,KB)); }//<summary>///decrypt string with the given key string///</summary>//<param name= "original" > Redaction </param>// /<param name= "key" > Key </param>//<returns> Clear text </returns> public static string Decrypt (string or  Iginal, string key) {return Decrypt (Original,key,system.text.encoding.default); }///<summary>///Use the given key string to decrypt string, return the specified encoding in plaintext///</summary>//<param name= "Encrypted" > Redaction </p aram>//<param name= "key" > Key </param>//<param name= "encoding" > character encoding scheme </param>//<re turns> plaintext </returns> 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)); } #endregion #region Use the default key string to encrypt/decrypt/byte[]//<summary>///Use default key string to decrypt byte[]///</summary>//< param name= "Encrypted" > redaction </param>//<param name= "key" > Key </param>//<returns> plaintext </ returns> public static byte[] Decrypt (byte[] encrypted) {byte[] key = System.Text.Encoding.Default.GetBytes ("Share   Js.com ");  Return Decrypt (Encrypted,key); }///<summary>///Use the default key string to encrypt///</summary>//<param name= "original" > Raw data </param>//&L T;param name= "key" > Key </param>//<returns> redaction </returns> public static byte[] Encrypt (byte[]   Original) {byte[] key = System.Text.Encoding.Default.GetBytes ("sharejs.com");  Return Encrypt (Original,key); } #endregion #region Encrypt/decrypt with the given key/byte[]/<summary>//Generate MD5 Summary///</summary>/<param name= "original" > Data source </param>//<returns > Summary </returns> public static byte[] MakeMD5 (byte[] original) {MD5CryptoServiceProvider hashmd5 = new Md5crypt   Oserviceprovider ();   byte[] Keyhash = Hashmd5.computehash (original);   HASHMD5 = null;  return keyhash; }///<summary>///Use a given key to encrypt///</summary>/<param name= "original" > Clear text </param>//<par Am Name= "key" > Key </param>//<returns> redaction </returns> public static byte[] Encrypt (byte[] original, b   Yte[] key) {TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider (); Des.   Key = MakeMD5 (key); Des.   Mode = CIPHERMODE.ECB; Return DES. CreateEncryptor (). TransformFinalBlock (original, 0, original.  Length); }///<summary>///Use the given key to decrypt the data///</summary>//<param name= "Encrypted" > redaction </param>//< param name= "key" > Key </param>//&LT;RETURNS&Gt; plaintext </returns> public static byte[] Decrypt (byte[] encrypted, byte[] key) {TripleDESCryptoServiceProvider des =   New TripleDESCryptoServiceProvider (); Des.   Key = MakeMD5 (key); Des.   Mode = CIPHERMODE.ECB; Return DES. CreateDecryptor (). TransformFinalBlock (encrypted, 0, encrypted.  Length); } #endregion}}

I hope this article is helpful to everyone's C # programming.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # implements an instance of Base64-based cryptographic decryption class

This address: http://www.paobuke.com/develop/c-develop/pbk23065.html






Related content C # implementation software function instance code C # get mouse in the ListView right-click cell content method How to use formal expressions to get matching data in C # Examples of the instantiated use of Delegates in C # programming
In-depth parsing of the abstract abstraction Class C # in C # Implementation of asynchronous connection to a SQL Server database file path in C # get function and file name getting functions Summary C # method for merging multiple Word documents

C # implements an instance of Base64-based cryptographic decryption class

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.