// JavaScript //The btoa() function decodes Base64 strings in web applications. const encodedString = btoa("Some encoded string"); console.log(encodedString); // Output: U29tZSBlbmNvZGVkIHN0cmluZw==
# Python # The base64.b64decode() function converts Base64 text into its original binary format. import base64 original_str = "Some encoded string" encoded_bytes= base64.b64encode(original_str.encode("utf-8")) print(encoded_str) # Output: U29tZSBlbmNvZGVkIHN0cmluZw==
// PHP // The base64_decode() function allows web developers to process encoded data. $encoded_str = "U29tZSBlbmNvZGVkIHN0cmluZw=="; $decoded_str = base64_decode($encoded_str); echo $decoded_str; // Output: Some encoded string
// Java // The Base64.getEncoder().encodeToString() method efficiently encodes text into Base64. import java.util.Base64; public class Main { public static void main(String[] args) { String originalStr = "Some encoded string"; String encodedStr = Base64.getEncoder().encodeToString(originalStr.getBytes()); System.out.println(encodedStr); // Output: U29tZSBlbmNvZGVkIHN0cmluZw== } }
// C# // The Convert.ToBase64String() method encodes binary data into a Base64 string. using System; class Program{ static void Main() { string original = "string"; // Original string to encode byte[] bytes = System.Text.Encoding.UTF8.GetBytes(original); // Convert string to bytes string encoded = Convert.ToBase64String(bytes); // Encode bytes to Base64 Console.WriteLine(encoded); // Output: c3RyaW5n } }
# Ruby # The Base64.encode64() method encodes a string into Base64 format. require 'base64'original = 'string' # Original string to encode encoded = Base64.encode64(original) # Encode string to Base64 puts encoded # Output: c3RyaW5n
-- MySQL -- The TO_BASE64() function encodes a string into Base64 format. SELECT TO_BASE64('string') AS encoded; -- Output: c3RyaW5n
-- PostgreSQL -- The encode() function encodes binary data using the specified format, like 'base64'. SELECT encode('string'::bytea, 'base64') AS encoded; -- Output: c3RyaW5n
# Linux CLI # The base64 command encodes input into Base64 format. # The -n flag prevents echo from adding a newline character. echo -n 'string' | base64 # Output: c3RyaW5n