1//Encode
2echo 'linuxhint.com' | base64
3
4//Decode
5echo 'bGludXhoaW50LmNvbQo=' | base64 --decode
1var string = "Hello folks how are you doing today?";
2var encodedString = btoa(string); // Base64 encode the String
3var decodedString = atob(encodedString); // Base64 decode the String
4
1// Define the string
2var string = 'Hello World!';
3
4// Encode the String
5var encodedString = btoa(string);
6console.log(encodedString); // Outputs: "SGVsbG8gV29ybGQh"
7
8// Decode the String
9var decodedString = atob(encodedString);
10console.log(decodedString); // Outputs: "Hello World!"
11
1class Program
2{
3 static void Main(string[] args)
4 {
5 var account = new ExternalAccount() { Name = "Someone" };
6 string json = JsonConvert.SerializeObject(account);
7 string base64EncodedExternalAccount = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
8 byte[] byteArray = Convert.FromBase64String(base64EncodedExternalAccount);
9
10 string jsonBack = Encoding.UTF8.GetString(byteArray);
11 var accountBack = JsonConvert.DeserializeObject<ExternalAccount>(jsonBack);
12 Console.WriteLine(accountBack.Name);
13 Console.ReadLine();
14 }
15}
16
17[Serializable]
18public class ExternalAccount
19{
20 public string Name { get; set; }
21}
1const fromBase64toString = (data) => {
2 return decodeURIComponent(
3 atob(data)
4 .split("")
5 .map(function (c) {
6 return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
7 })
8 .join("")
9 );
10 };