import java.util.Base64; public class Base64Example { public static void main(String[] args) { String originalData = "Hello, World!"; String encodedData = Base64.getEncoder().encodeToString(originalData.getBytes()); byte[] decodedData = Base64.getDecoder().decode(encodedData); String decodedString = new String(decodedData); } } import org.apache.commons.codec.binary.Base64; public class Base64Example { public static void main(String[] args) { String originalData = "Hello, World!"; byte[] encodedData = Base64.encodeBase64(originalData.getBytes()); byte[] decodedData = Base64.decodeBase64(encodedData); String decodedString = new String(decodedData); } } import java.util.Base64; public class Base64Example { public static void main(String[] args) { String originalData = "Hello, World!"; String customCharacterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; Base64.Encoder encoder = Base64.getEncoder().withoutPadding().withCharset(customCharacterSet); String encodedData = encoder.encodeToString(originalData.getBytes()); Base64.Decoder decoder = Base64.getDecoder().withCharset(customCharacterSet); byte[] decodedData = decoder.decode(encodedData); String decodedString = new String(decodedData); } }


上一篇:
下一篇:
切换中文