Base64: Encoding and Decoding Strings with Base64
The Base64 encoding scheme is a way to represent binary data in an ASCII string. It is often used to encode data for transmission over networks or storage in databases.
Decoding and Encoding a String
To decode and encode a string using Base64, you can use the Java Base64 class. Here's the corrected code:
import java.util.Base64; String source = "password"; byte[] byteArray = source.getBytes(StandardCharsets.UTF_8); // Encode byte[] encodedBytes = Base64.getEncoder().encode(byteArray); String encodedString = new String(encodedBytes); System.out.println("Encoded String: " + encodedString); // Decode byte[] decodedBytes = Base64.getDecoder().decode(encodedBytes); String decodedString = new String(decodedBytes); System.out.println("Decoded String: " + decodedString);
Encoding Process
Decoding Process
The above is the detailed content of How Can I Encode and Decode Strings Using Base64 in Java?. For more information, please follow other related articles on the PHP Chinese website!