Des symmetric plus decryption, AES rijndaelmanaged plus decryption, Base64 encryption and decryption, MD5 encryption and other operational auxiliary classes Encodehelper

Source: Internet
Author: User
Tags decrypt md5 encryption

<summary>

Use default encryption

</summary>

<param name= "StrText" ></param>

<returns></returns>

public static string Desencrypt (String strText)

<summary>

Use default decryption

</summary>

<param name= "StrText" > Decrypt string </param>

<returns></returns>

public static string Desdecrypt (String strText)

<summary>

Encrypt the string, note that the length of the Strencrkey is 8 bits

</summary>

<param name= "StrText" > Strings to be encrypted </param>

<param name= "Strencrkey" > Encryption key </param>

<returns></returns>

public static string Desencrypt (String strText, String strencrkey)

<summary>

Decrypt the string, note that the length of the Strencrkey is 8 bits

</summary>

<param name= "StrText" > String to Decrypt </param>

<param name= "Sdecrkey" > Decryption key </param>

<returns> decrypted String </returns>

public static string Desdecrypt (String strText, String sdecrkey)

<summary>

Encrypt the data file, note that the length of the Strencrkey is 8 bits

</summary>

<param name= "M_infilepath" > File path to be encrypted </param>

<param name= "M_outfilepath" > Output file path </param>

<param name= "Strencrkey" > Encryption key </param>

public static void Desencrypt (String m_infilepath, String M_outfilepath, String strencrkey)

<summary>

Decrypt the data file, note that the length of the Strencrkey is 8 bits

</summary>

<param name= "M_infilepath" > File path to be decrypted </param>

<param name= "M_outfilepath" > Output path </param>

<param name= "Sdecrkey" > Decryption key </param>

public static void Desdecrypt (String m_infilepath, String M_outfilepath, String sdecrkey)

#endregion

AES RijndaelManaged encryption and decryption #region symmetric encryption algorithm

<summary>

Symmetric encryption Algorithm AES rijndaelmanaged encryption (RijndaelManaged (AES) algorithm is a block-type encryption algorithm)

</summary>

<param name= "encryptstring" > Strings to be encrypted </param>

<returns> Encrypt result string </returns>

public static string Aes_encrypt (String encryptstring)

<summary>

Symmetric encryption Algorithm AES rijndaelmanaged encryption (RijndaelManaged (AES) algorithm is a block-type encryption algorithm)

</summary>

<param name= "encryptstring" > Strings to be encrypted </param>

<param name= "Encryptkey" > Encryption key, required half-width character </param>

<returns> Encrypt result string </returns>

public static string Aes_encrypt (String encryptstring, String encryptkey)

<summary>

Symmetric encryption algorithm AES RijndaelManaged decryption string

</summary>

<param name= "Decryptstring" > String to Decrypt </param>

<returns> decryption succeeded in returning the decrypted string, failed to return to the source string </returns>

public static string Aes_decrypt (String decryptstring)

<summary>

Symmetric encryption algorithm AES RijndaelManaged decryption string

</summary>

<param name= "Decryptstring" > String to Decrypt </param>

<param name= "Decryptkey" > Decryption key, same as encryption key </param>

<returns> decryption succeeded in returning the decrypted string, failed to return null </returns>

public static string Aes_decrypt (String decryptstring, String decryptkey)

<summary>

Encrypting File Streams

</summary>

<param name= "FS" > File Flow </param>

<returns></returns>

public static CryptoStream Aes_encryptstrream (FileStream FS, string Decryptkey)

<summary>

Decrypting a file stream

</summary>

<param name= "FS" > File Flow </param>

<returns></returns>

public static CryptoStream Aes_decryptstream (FileStream FS, string Decryptkey)

<summary>

Encrypt the specified file

</summary>

<param name= "inputfile" > Input file </param>

<param name= "OutputFile" > Output file </param>

<returns></returns>

public static bool Aes_encryptfile (string inputfile, String OutputFile)

<summary>

Unzip the specified file

</summary>

<param name= "inputfile" > Input file </param>

<param name= "OutputFile" > Output file </param>

<returns></returns>

public static bool Aes_decryptfile (string inputfile, String OutputFile)

#endregion

#region Base64 Encryption and decryption

<summary>

Base64 is a positional method that uses 64 radicals. It uses a maximum of 2 to represent only printable ASCII characters.

This makes it usable as the code for the email. The variables in Base64 use characters A-Z, A-Z, and 0-9,

This is a total of 62 characters, used as the beginning of the 64 digits, the last two used as the number of symbols in different

Different in the system.

BASE64 encryption

</summary>

<param name= "str" >base64 Way Encryption string </param>

<returns></returns>

public static string Base64encrypt (String str)

<summary>

Base64 decrypting a string

</summary>

<param name= "str" > string to Decrypt </param>

<returns></returns>

public static string Base64decrypt (String str)

#endregion

#region MD5 Encryption

<summary>

Using MD5 to encrypt strings

</summary>

<param name= "StrText" > Strings to be encrypted </param>

<RETURNS>MD5 Encrypted String </returns>

public static string Md5encrypt (String strText)

<summary>

Hash table with MD5 encryption

</summary>

<param name= "Input" > string to encrypt </param>

<returns></returns>

public static string Md5encrypthash (String input)

<summary>

Using MD5 encryption as a 16 binary string

</summary>

<param name= "Input" > string to encrypt </param>

<returns></returns>

public static string Md5encrypthashhex (String input)

<summary>

MD5 three-time encryption algorithm. Calculation process: (QQ use)

1. Verify code to uppercase

2. Use this method to encrypt the password three times, with the verification code to overlay

3. Then MD5 the superimposed content again to get the value of the final verification code

</summary>

<param name= "S" ></param>

<returns></returns>

public static string Encyptmd5_3_16 (string s)

#endregion

<summary>

SHA256 function

</summary>

<param name= "str" > Raw string </param>

<returns>sha256 result (returns a string with a length of 44 bytes) </returns>

public static string SHA256 (String str)

<summary>

Encrypt strings (using MD5+BASE64 hybrid encryption)

</summary>

<param name= "Input" > Strings to be encrypted </param>

<returns></returns>

public static string encryptstring (String input)

<summary>

Decrypt the encrypted string (using MD5+BASE64 hybrid encryption)

</summary>

<param name= "Input" > string to Decrypt </param>

<param name= "ThrowException" > Decryption failure thrown exception </param>

<returns></returns>

public static string decryptstring (string input, bool throwexception)

、、、

<summary>

Encrypt string

</summary>

<returns></returns>

private string Encodepassword (String passwordtext)

{

Return Encodehelper.md5encrypt (Passwordtext);
}

、、、

private void Btnencrypt_click (object sender, EventArgs e)

{

String original = "Test cryptographic string";

Console.WriteLine ("Original:" + original);

String encrypt = encodehelper.sha256 (original);

Console.WriteLine ("encodehelper.sha256" + Encrypt);

Des plus decryption

Encrypt = Encodehelper.desencrypt (original);

Console.WriteLine ("Encodehelper.desencrypt:" + encrypt);

String decrypt = Encodehelper.desdecrypt (encrypt);

Console.WriteLine ("Encodehelper.desdecrypt:" + decrypt);

MD5 encryption

Encrypt = Encodehelper.md5encrypt (original);

Console.WriteLine ("Encodehelper.md5encrypt:" + encrypt);

Encrypt = Encodehelper.md5encrypthash (original);

Console.WriteLine ("Encodehelper.md5encrypthash:" + encrypt);

Encrypt = Encodehelper.md5encrypthashhex (original);

Console.WriteLine ("Encodehelper.md5encrypthashhex" + Encrypt);

Encrypt = Encodehelper.encyptmd5_3_16 (original);

Console.WriteLine ("Encodehelper.encyptmd5_3_16:" + encrypt);

Base64 Plus decryption

Encrypt = Encodehelper.base64encrypt (original);

Console.WriteLine ("Encodehelper.base64encrypt" + Encrypt);

Decrypt = Encodehelper.base64encrypt (encrypt);

Console.WriteLine ("Encodehelper.base64encrypt" + decrypt);

Encrypt = Encodehelper.aes_encrypt (original);

Console.WriteLine ("Encodehelper.aes_encrypt" + Encrypt);

Decrypt = Encodehelper.aes_decrypt (encrypt);
Console.WriteLine ("Encodehelper.aes_decrypt" + Decrypt);

、、、、、

Des symmetric plus decryption, AES rijndaelmanaged plus decryption, Base64 encryption and decryption, MD5 encryption and other operational auxiliary classes Encodehelper

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.