Skip to content

Instantly share code, notes, and snippets.

@ivanelianto
Last active November 24, 2019 09:48
Show Gist options
  • Save ivanelianto/cd50ed32446fa20f4d4ad7ffbf29903e to your computer and use it in GitHub Desktop.
Save ivanelianto/cd50ed32446fa20f4d4ad7ffbf29903e to your computer and use it in GitHub Desktop.
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