EnCode and Decode Base64 String
This article will helps to convert the Base64 string into Encode or Decode.
The Purpose of the Encoding is to used to convert our data as very secure manner and convert as Decoded string when you needed.
This Encode and Decode Methods are used to convert our Base64 string as Encoded format and we can decode our encoded string when you needed. This will helps to encrypt our password and security number as encoded format and we can store it into database. whenever we want to get the original string then we can Decode it.
This is very easiest way to encode and decode our string and no need to write any complicated algorithms.
Below are the sample code:Encode
public static string Base64Encode(string plainText) {
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}Decode
public static string Base64Decode(string base64EncodedData) {
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
You just call your method like below
Base64Encode("Simiyon");
The Out Put is: U2ltaXlvbg==
Base64Decode("U2ltaXlvbg==")
The Out Put is: Simiyon