Java Code Examples for java.util.Base64#getUrlDecoder()
The following examples show how to use
java.util.Base64#getUrlDecoder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Base64Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * Check decoding sample non-ASCII byte[] values from a {@link #TABLE_2} * (url safe) encoded String. */ public void testDecoder_nonPrintableBytes_url() throws Exception { Decoder decoder = Base64.getUrlDecoder(); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 0, decoder.decode("")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 1, decoder.decode("_w==")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 2, decoder.decode("_-4=")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 3, decoder.decode("_-7d")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 4, decoder.decode("_-7dzA==")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 5, decoder.decode("_-7dzLs=")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 6, decoder.decode("_-7dzLuq")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 7, decoder.decode("_-7dzLuqmQ==")); assertArrayPrefixEquals(SAMPLE_NON_ASCII_BYTES, 8, decoder.decode("_-7dzLuqmYg=")); }
Example 2
Source File: JWT.java From fido2 with GNU Lesser General Public License v2.1 | 5 votes |
public JWT(String input) { System.out.println("JWT: " + input); Base64.Decoder decoder = Base64.getUrlDecoder(); String[] jwtParts = input.split("\\."); this.header = jwtParts[0]; this.body = jwtParts[1]; this.signature = decoder.decode(jwtParts[2]); }
Example 3
Source File: Credential.java From selenium with Apache License 2.0 | 5 votes |
/** * Creates a credential from a map. */ public static Credential fromMap(Map<String, Object> map) { Base64.Decoder decoder = Base64.getUrlDecoder(); return new Credential(decoder.decode((String) map.get("credentialId")), (boolean) map.get("isResidentCredential"), (String) map.get("rpId"), new PKCS8EncodedKeySpec(decoder.decode((String) map.get("privateKey"))), map.get("userHandle") == null ? null : decoder.decode((String) map.get("userHandle")), ((Long) map.get("signCount")).intValue()); }
Example 4
Source File: Base64Test.java From j2objc with Apache License 2.0 | 5 votes |
public void testEncoder_lineLength() throws Exception { String in_56 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"; String in_57 = in_56 + "e"; String in_58 = in_56 + "ef"; String in_59 = in_56 + "efg"; String in_60 = in_56 + "efgh"; String in_61 = in_56 + "efghi"; String prefix = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5emFi"; String out_56 = prefix + "Y2Q="; String out_57 = prefix + "Y2Rl"; String out_58 = prefix + "Y2Rl\r\nZg=="; String out_59 = prefix + "Y2Rl\r\nZmc="; String out_60 = prefix + "Y2Rl\r\nZmdo"; String out_61 = prefix + "Y2Rl\r\nZmdoaQ=="; Encoder encoder = Base64.getMimeEncoder(); Decoder decoder = Base64.getMimeDecoder(); assertEquals("", encodeFromAscii(encoder, decoder, "")); assertEquals(out_56, encodeFromAscii(encoder, decoder, in_56)); assertEquals(out_57, encodeFromAscii(encoder, decoder, in_57)); assertEquals(out_58, encodeFromAscii(encoder, decoder, in_58)); assertEquals(out_59, encodeFromAscii(encoder, decoder, in_59)); assertEquals(out_60, encodeFromAscii(encoder, decoder, in_60)); assertEquals(out_61, encodeFromAscii(encoder, decoder, in_61)); encoder = Base64.getUrlEncoder(); decoder = Base64.getUrlDecoder(); assertEquals(out_56.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_56)); assertEquals(out_57.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_57)); assertEquals(out_58.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_58)); assertEquals(out_59.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_59)); assertEquals(out_60.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_60)); assertEquals(out_61.replaceAll("\r\n", ""), encodeFromAscii(encoder, decoder, in_61)); }
Example 5
Source File: Base64Test.java From j2objc with Apache License 2.0 | 5 votes |
/** * Checks decoding of bytes containing a value outside of the allowed * {@link #TABLE_2 url alphabet}. */ public void testDecoder_extraChars_url() throws Exception { Decoder urlDecoder = Base64.getUrlDecoder(); // uses Table 2 // Check failure cases common to both RFC4648 table 1 and table 2 decoding. checkDecoder_extraChars_common(urlDecoder); // Tests characters that are part of RFC4848 Table 1 but not Table 2. assertDecodeThrowsIAe(urlDecoder, "/aGVsbG8sIHdvcmx"); assertDecodeThrowsIAe(urlDecoder, "aGV/sbG8sIHdvcmx"); assertDecodeThrowsIAe(urlDecoder, "aGVsbG8sIHdvcmx/"); }
Example 6
Source File: TestBase64.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(new Runnable() { public void run() { dec.decode(srcBytes); }}); // decode(String) checkIAE(new Runnable() { public void run() { dec.decode(srcStr); }}); // decode(ByteBuffer) checkIAE(new Runnable() { public void run() { dec.decode(srcBB); }}); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 7
Source File: TestBase64.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(new Runnable() { public void run() { dec.decode(srcBytes); }}); // decode(String) checkIAE(new Runnable() { public void run() { dec.decode(srcStr); }}); // decode(ByteBuffer) checkIAE(new Runnable() { public void run() { dec.decode(srcBB); }}); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 8
Source File: TestBase64.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(new Runnable() { public void run() { dec.decode(srcBytes); }}); // decode(String) checkIAE(new Runnable() { public void run() { dec.decode(srcStr); }}); // decode(ByteBuffer) checkIAE(new Runnable() { public void run() { dec.decode(srcBB); }}); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 9
Source File: Java7Base64UrlSafeEncoder.java From Smack with Apache License 2.0 | 4 votes |
private Java7Base64UrlSafeEncoder() { encoder = Base64.getUrlEncoder(); decoder = Base64.getUrlDecoder(); }
Example 10
Source File: TestBase64.java From hottub with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(new Runnable() { public void run() { dec.decode(srcBytes); }}); // decode(String) checkIAE(new Runnable() { public void run() { dec.decode(srcStr); }}); // decode(ByteBuffer) checkIAE(new Runnable() { public void run() { dec.decode(srcBB); }}); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 11
Source File: TestBase64.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(() -> dec.decode(srcBytes)); // decode(String) checkIAE(() -> dec.decode(srcStr)); // decode(ByteBuffer) checkIAE(() -> dec.decode(srcBB)); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 12
Source File: Base64Test.java From j2objc with Apache License 2.0 | 4 votes |
public void testRoundTrip_wrap_url() throws Exception { Encoder encoder = Base64.getUrlEncoder(); Decoder decoder = Base64.getUrlDecoder(); checkRoundTrip_wrapInputStream(encoder, decoder); }
Example 13
Source File: TestBase64.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(() -> dec.decode(srcBytes)); // decode(String) checkIAE(() -> dec.decode(srcStr)); // decode(ByteBuffer) checkIAE(() -> dec.decode(srcBB)); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } // anything left after padding is "invalid"/IAE, if // not MIME. In case of MIME, non-base64 character(s) // is ignored. checkIAE(() -> Base64.getDecoder().decode("AA==\u00D2")); checkIAE(() -> Base64.getUrlDecoder().decode("AA==\u00D2")); Base64.getMimeDecoder().decode("AA==\u00D2"); }
Example 14
Source File: TestBase64.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(() -> dec.decode(srcBytes)); // decode(String) checkIAE(() -> dec.decode(srcStr)); // decode(ByteBuffer) checkIAE(() -> dec.decode(srcBB)); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 15
Source File: TokenFactory.java From multiapps-controller with Apache License 2.0 | 4 votes |
private String decode(String string) { Decoder decoder = Base64.getUrlDecoder(); return new String(decoder.decode(string), StandardCharsets.UTF_8); }
Example 16
Source File: TestBase64.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(new Runnable() { public void run() { dec.decode(srcBytes); }}); // decode(String) checkIAE(new Runnable() { public void run() { dec.decode(srcStr); }}); // decode(ByteBuffer) checkIAE(new Runnable() { public void run() { dec.decode(srcBB); }}); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 17
Source File: TestBase64.java From native-obfuscator with GNU General Public License v3.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(() -> dec.decode(srcBytes)); // decode(String) checkIAE(() -> dec.decode(srcStr)); // decode(ByteBuffer) checkIAE(() -> dec.decode(srcBB)); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 18
Source File: TestBase64.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(() -> dec.decode(srcBytes)); // decode(String) checkIAE(() -> dec.decode(srcStr)); // decode(ByteBuffer) checkIAE(() -> dec.decode(srcBB)); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 19
Source File: TestBase64.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private static void testMalformedPadding() throws Throwable { Object[] data = new Object[] { "$=#", "", 0, // illegal ending unit "A", "", 0, // dangling single byte "A=", "", 0, "A==", "", 0, "QUJDA", "ABC", 4, "QUJDA=", "ABC", 4, "QUJDA==", "ABC", 4, "=", "", 0, // unnecessary padding "QUJD=", "ABC", 4, //"ABC".encode() -> "QUJD" "AA=", "", 0, // incomplete padding "QQ=", "", 0, "QQ=N", "", 0, // incorrect padding "QQ=?", "", 0, "QUJDQQ=", "ABC", 4, "QUJDQQ=N", "ABC", 4, "QUJDQQ=?", "ABC", 4, }; Base64.Decoder[] decs = new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() }; for (Base64.Decoder dec : decs) { for (int i = 0; i < data.length; i += 3) { final String srcStr = (String)data[i]; final byte[] srcBytes = srcStr.getBytes("ASCII"); final ByteBuffer srcBB = ByteBuffer.wrap(srcBytes); byte[] expected = ((String)data[i + 1]).getBytes("ASCII"); int pos = (Integer)data[i + 2]; // decode(byte[]) checkIAE(() -> dec.decode(srcBytes)); // decode(String) checkIAE(() -> dec.decode(srcStr)); // decode(ByteBuffer) checkIAE(() -> dec.decode(srcBB)); // wrap stream checkIOE(new Testable() { public void test() throws IOException { try (InputStream is = dec.wrap(new ByteArrayInputStream(srcBytes))) { while (is.read() != -1); } }}); } } }
Example 20
Source File: JWT.java From fido2 with GNU Lesser General Public License v2.1 | 4 votes |
public JsonObject getBody() throws UnsupportedEncodingException { Base64.Decoder decoder = Base64.getUrlDecoder(); return stringToJson(decoder.decode(body)); }