1515
1616import java .net .URLDecoder ;
1717import java .nio .charset .StandardCharsets ;
18- import java .util .Base64 ;
18+
19+ import org .apache .commons .codec .binary .Base64 ;
1920
2021/**
2122 * Utilities for encoding, i.e., Base64, URI and JSON
2223 */
2324public abstract class Encoding {
25+
2426 private Encoding () {} /* ensures cannot be constructed */
2527
2628 /**
@@ -29,7 +31,7 @@ private Encoding() {} /* ensures cannot be constructed */
2931 * @return the encoded byte array
3032 */
3133 public static byte [] base64BasicEncode (byte [] input ) {
32- return Base64 .getEncoder (). encode (input );
34+ return Base64 .encodeBase64 (input );
3335 }
3436
3537 /**
@@ -38,7 +40,7 @@ public static byte[] base64BasicEncode(byte[] input) {
3840 * @return the encoded byte array
3941 */
4042 public static String base64BasicEncodeToString (byte [] input ) {
41- return Base64 .getEncoder (). encodeToString (input );
43+ return Base64 .encodeBase64String (input );
4244 }
4345
4446 /**
@@ -47,8 +49,7 @@ public static String base64BasicEncodeToString(byte[] input) {
4749 * @return the encoded byte array
4850 */
4951 public static String base64BasicEncodeToString (String input ) {
50- return Base64 .getEncoder ()
51- .encodeToString (input .getBytes (StandardCharsets .UTF_8 ));
52+ return Base64 .encodeBase64String (input .getBytes (StandardCharsets .UTF_8 ));
5253 }
5354
5455 /**
@@ -57,7 +58,7 @@ public static String base64BasicEncodeToString(String input) {
5758 * @return the encoded byte array
5859 */
5960 public static byte [] base64UrlEncode (byte [] input ) {
60- return Base64 .getUrlEncoder (). withoutPadding (). encode (input );
61+ return Base64 .encodeBase64URLSafe (input );
6162 }
6263
6364 /**
@@ -66,7 +67,7 @@ public static byte[] base64UrlEncode(byte[] input) {
6667 * @return the encoded byte array
6768 */
6869 public static String base64UrlEncodeToString (byte [] input ) {
69- return Base64 .getUrlEncoder (). withoutPadding (). encodeToString (input );
70+ return Base64 .encodeBase64URLSafeString (input );
7071 }
7172
7273 /**
@@ -75,9 +76,7 @@ public static String base64UrlEncodeToString(byte[] input) {
7576 * @return the encoded byte array
7677 */
7778 public static String base64UrlEncodeToString (String input ) {
78- return Base64 .getUrlEncoder ()
79- .withoutPadding ()
80- .encodeToString (input .getBytes (StandardCharsets .UTF_8 ));
79+ return Base64 .encodeBase64URLSafeString (input .getBytes (StandardCharsets .UTF_8 ));
8180 }
8281
8382 /**
@@ -86,7 +85,7 @@ public static String base64UrlEncodeToString(String input) {
8685 * @return the decoded byte array
8786 */
8887 public static byte [] base64BasicDecode (byte [] input ) {
89- return Base64 .getDecoder (). decode (input );
88+ return Base64 .decodeBase64 (input );
9089 }
9190
9291 /**
@@ -95,7 +94,7 @@ public static byte[] base64BasicDecode(byte[] input) {
9594 * @return the decoded byte array
9695 */
9796 public static byte [] base64BasicDecode (String input ) {
98- return Base64 .getDecoder (). decode (input );
97+ return Base64 .decodeBase64 (input );
9998 }
10099
101100 /**
@@ -104,7 +103,7 @@ public static byte[] base64BasicDecode(String input) {
104103 * @return the decoded string
105104 */
106105 public static String base64BasicDecodeToString (String input ) {
107- return new String (Base64 .getDecoder (). decode (input ));
106+ return new String (Base64 .decodeBase64 (input ));
108107 }
109108
110109 /**
@@ -113,7 +112,7 @@ public static String base64BasicDecodeToString(String input) {
113112 * @return the decoded byte array
114113 */
115114 public static byte [] base64UrlDecode (byte [] input ) {
116- return Base64 .getUrlDecoder (). decode (input );
115+ return Base64 .decodeBase64 (input );
117116 }
118117
119118 /**
@@ -122,7 +121,7 @@ public static byte[] base64UrlDecode(byte[] input) {
122121 * @return the decoded byte array
123122 */
124123 public static byte [] base64UrlDecode (String input ) {
125- return Base64 .getUrlDecoder (). decode (input );
124+ return Base64 .decodeBase64 (input );
126125 }
127126
128127 /**
@@ -131,7 +130,7 @@ public static byte[] base64UrlDecode(String input) {
131130 * @return the decoded string
132131 */
133132 public static String base64UrlDecodeToString (String input ) {
134- return new String (Base64 .getUrlDecoder (). decode (input ));
133+ return new String (Base64 .decodeBase64 (input ));
135134 }
136135
137136 /**
0 commit comments