Last active
November 24, 2019 09:48
-
-
Save ivanelianto/cd50ed32446fa20f4d4ad7ffbf29903e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.UnsupportedEncodingException; | |
import java.util.Base64; | |
public class Base64EncodingManager { | |
public static Base64EncodingManager instance; | |
private Base64EncodingManager() { | |
} | |
public static Base64EncodingManager getInstance() { | |
if (instance == null) | |
instance = new Base64EncodingManager(); | |
return instance; | |
} | |
public String decode(String encodedText) { | |
byte[] decodedBytes = Base64.getMimeDecoder().decode(encodedText); | |
String result = ""; | |
try { | |
result = new String(decodedBytes, "utf-8"); | |
} catch (UnsupportedEncodingException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return result; | |
} | |
public String encode(String plainText) { | |
String result = ""; | |
try { | |
result = Base64.getMimeEncoder().encodeToString(plainText.getBytes("utf-8")); | |
} catch (UnsupportedEncodingException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment