![]() |
Base64 encoding allows encoding binary data as text strings for safe transport, at the cost of larger data size. It is commonly used when there is a need to encode binary data that needs to be stored or transferred via media that are designed to deal with textual data (like transporting images inside an XML, JSON document, etc.). How to Convert a String to Base64 Encoded String in Java?In Java, the java.util.Base64 class provides static methods to encode and decode between binary and base64 formats. The encode() and decode() methods are used. Syntax: String Base64format= Base64.getEncoder().encodeToString("String".getBytes()); Example to convert a String to base64 encoded String:Java
Output
Encoding Done: Original String: GeeksForGeeks Base64 Encoded String: R2Vla3NGb3JHZWVrcw== Decoding Done: Base64 Encoded String : R2Vla3NGb3JHZWVrcw== Original String: GeeksForGeeks Explanation of the above Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |