Method One
Class Base64helper {///<summary>///Base64 encryption, UTF8 encoded encryption///</summary>///<param Name = ' source ' > plaintext to be encrypted </param>///<returns> encrypted string </returns> public static string Base64Encode (str
ing source) {return Base64Encode (Encoding.UTF8, source); }///<summary>///Base64 encryption///</summary>///<param name= "Encodetype" > Encryption using the Encoding method </ param>///<param name= "source" > Encrypted plaintext </param>///<returns></returns> public Stati C String Base64Encode (Encoding Encodetype, String source) {string encode = string.
Empty;
byte[] bytes = encodetype.getbytes (source);
try {encode = convert.tobase64string (bytes);
catch {encode = source;
return encode; ///<summary>///Base64 decryption, using UTF8 encoding method to decrypt///</summary>///<param name= "ResULt > Ciphertext to decrypt </param>///<returns> decrypted string </returns> public static string Base64decode (String re
Sult) {return Base64decode (Encoding.UTF8, result); }///<summary>///Base64 decryption///</summary>///<param name= "Encodetype" > Decryption using the Encoding method, note and add Dense time in the same way </param>///<param name= "Result" > to decrypt the ciphertext </param>///<returns> decrypted string </returns > public static string Base64decode (Encoding encodetype, string result) {string decode = string.
Empty;
byte[] bytes = convert.frombase64string (result);
try {decode = encodetype.getstring (bytes);
catch {decode = result;
return decode; }
}
Method Two
There is an encryption method: plaintext encrypted after the generation length is 24-bit ciphertext, and ciphertext to = end. After the query found that everyone said this encryption method is BASE64 encryption, but this encryption method in one of the BASE64 encryption, the specific code is as follows.
Class program
{
static void Main (string[] args)
{
string original = "123456";
var md5 = bitconverter.tostring (new System.Security.Cryptography.MD5CryptoServiceProvider (). ComputeHash (Encoding.Default.GetBytes (original))). Replace ("-", ""). ToLower ();
Console.WriteLine ("md5=" + MD5);
B64 is a cipher with a length of 24 bits at the end of =
b64 = convert.tobase64string (new System.Security.Cryptography.MD5CryptoServiceProvider (). ComputeHash (Encoding.Default.GetBytes (original)));
Console.WriteLine ("b64=" + b64);
var dec = bitconverter.tostring (New System.Security.Cryptography.FromBase64Transform (). TransformFinalBlock (Encoding.Default.GetBytes (b64), 0, Encoding.Default.GetBytes (b64). Length)). Replace ("-", ""). ToLower ();
Console.WriteLine ("dec=" + dec);
Console.ReadLine ();
}