. NET 3DES Decryption

Source: Internet
Author: User

String str= "xxxxxxxxxxxxxx";//need to decrypt data

3DES key

String Deskey = "JLGDSGJDGDG";

3DES vector
String Desiv = "Sfasfsffa";

string result = Decrypt3des (Str,deskey,desiv, System.Security.Cryptography.CipherMode.CBC);//decryption result

#region 3DES decryption

<summary>
Des decryption
</summary>
<param name= "astrstring" > Encrypted string </param>
<param name= "Astrkey" > Key </param>
<param name= "IV" > Decryption vectors: Applicable only in CBC decryption mode </param>
<param name= "mode" > Operation mode </param> String IV = "12345678"
<returns> decrypted String </returns>
public string Decrypt3des (string astrstring, String Astrkey, String IV, Ciphermode mode = CIPHERMODE.CBC)
{
Try
{
var des = new TripleDESCryptoServiceProvider
{
Key = Encoding.UTF8.GetBytes (Astrkey),
Key =convert.frombase64string (Astrkey),
Key = Encoding.Default.GetBytes (Astrkey),
mode = mode,
Padding = PADDINGMODE.PKCS7
};
if (mode = = CIPHERMODE.CBC)
{
DES.IV = Encoding.UTF8.GetBytes (IV);
}
var desdecrypt = des. CreateDecryptor ();
var result = "";
byte[] buffer = convert.frombase64string (astrstring);
result = Encoding.UTF8.GetString (desdecrypt.transformfinalblock (buffer, 0, buffer. Length));
return result;
}
catch (Exception e)
{
return string. Empty;
}
}
#endregion

. NET 3DES Decryption

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.