-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathBase64.java
36 lines (27 loc) · 880 Bytes
/
Base64.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package cryptography.encoding.base64;
import cryptography.Mode;
public class Base64 {
public static void main(String[] args) {
}
public static String base64(String input, Mode mode) {
String output = "";
byte[] encode = input.getBytes();
byte[] decode;
/*
* Note, Cryptography application uses 'android.util.Base64;' implementation
* instead but works by the standard You can find Apache codec Base64 source
* code from link below
* https://github.com/apache/commons-codec/blob/master/src/main/java/org/apache/
* commons/codec/binary/Base64.java
*/
org.apache.commons.codec.binary.Base64 base64 = new org.apache.commons.codec.binary.Base64();
if (mode == Mode.ENCODE) {
output = base64.encodeToString(encode);
}
if (mode == Mode.DECODE) {
decode = base64.decode(input);
output = new String(decode);
}
return output;
}
}