How to Encode and Decode with Base64 and cryptor in C#

1
2


How to Encode and Decode with Base64 and cryptor in C#

// Base64
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
public static string Base64Decode(string base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}

// cryptor
byte[] source = Encoding.Unicode.GetBytes(String str);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MemoryStream ms = new MemoryStream() ;
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(DesKey, DesIV),
CryptoStreamMode.Write);
cs.Write(source, 0, source.Length);
cs.Close();
byte[] destination = ms.ToArray();
ms.Close();
textBox2.Text = Encoding.Unicode.GetString(destination);
textBox3.Text = “”;

TripleDESCryptoServiceProvider TDES = new TripleDESCryptoServiceProvider();
DesKey = TDES.Key;
DesIV = TDES.IV;

Thanks you!

Nguồn:https://wijstaanvooronzegrondrechten.org/

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here