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