Java Code Examples for java.util.Base64#getMimeEncoder()
The following examples show how to use
java.util.Base64#getMimeEncoder() .
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: SignedJarBuilder.java From buck with Apache License 2.0 | 6 votes |
/** * Creates a {@link SignedJarBuilder} with a given output stream, and signing information. * <p>If either <code>key</code> or <code>certificate</code> is <code>null</code> then * the archive will not be signed. * @param out the {@link OutputStream} where to write the Jar archive. * @param key the {@link PrivateKey} used to sign the archive, or <code>null</code>. * @param certificate the {@link X509Certificate} used to sign the archive, or * <code>null</code>. * @throws IOException * @throws NoSuchAlgorithmException */ public SignedJarBuilder(OutputStream out, PrivateKey key, X509Certificate certificate) throws IOException, NoSuchAlgorithmException { mOutputJar = new JarOutputStream(new BufferedOutputStream(out)); mOutputJar.setLevel(4); mKey = key; mCertificate = certificate; if (mKey != null && mCertificate != null) { mManifest = new Manifest(); Attributes main = mManifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (Android)"); mBase64Encoder = Base64.getMimeEncoder(); mMessageDigest = MessageDigest.getInstance(DIGEST_ALGORITHM); } }
Example 2
Source File: TestBase64Golden.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static void test1() throws Exception { byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); byte[] encoded = encoder.encode(src); Decoder decoder = Base64.getMimeDecoder(); byte[] decoded = decoder.decode(encoded); if (!Objects.deepEquals(src, decoded)) { throw new RuntimeException(); } }
Example 3
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 4
Source File: TestBase64Golden.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void test1() throws Exception { byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); byte[] encoded = encoder.encode(src); Decoder decoder = Base64.getMimeDecoder(); byte[] decoded = decoder.decode(encoded); if (!Objects.deepEquals(src, decoded)) { throw new RuntimeException(); } }
Example 5
Source File: TestBase64Golden.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private static void test1() throws Exception { byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); byte[] encoded = encoder.encode(src); Decoder decoder = Base64.getMimeDecoder(); byte[] decoded = decoder.decode(encoded); if (!Objects.deepEquals(src, decoded)) { throw new RuntimeException(); } }
Example 6
Source File: FileService.java From ADT_Frontend with MIT License | 5 votes |
/** * Returns the request headers for sending github account user name and * password to back-end */ private IHeaders getHttpHeadersForCredentials(String username, String password) { IHeaders headers = HeadersFactory.newHeaders(); IHeaders.IField userField = HeadersFactory.newField("Username", username); //$NON-NLS-1$ headers.addField(userField); Base64.Encoder encoder = Base64.getMimeEncoder(); IHeaders.IField passwordField = HeadersFactory.newField("Password", //$NON-NLS-1$ encoder.encodeToString(password.getBytes(StandardCharsets.UTF_8))); headers.addField(passwordField); return headers; }
Example 7
Source File: TestBase64.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 8
Source File: TestBase64.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 9
Source File: TestBase64.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 10
Source File: TestBase64.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 11
Source File: TestBase64Golden.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void test1() throws Exception { byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); byte[] encoded = encoder.encode(src); Decoder decoder = Base64.getMimeDecoder(); byte[] decoded = decoder.decode(encoded); if (!Objects.deepEquals(src, decoded)) { throw new RuntimeException(); } }
Example 12
Source File: TestBase64.java From native-obfuscator with GNU General Public License v3.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 13
Source File: TestBase64Golden.java From native-obfuscator with GNU General Public License v3.0 | 5 votes |
private static void test1() throws Exception { byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); byte[] encoded = encoder.encode(src); Decoder decoder = Base64.getMimeDecoder(); byte[] decoded = decoder.decode(encoded); if (!Objects.deepEquals(src, decoded)) { throw new RuntimeException(); } }
Example 14
Source File: TestBase64.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 15
Source File: TestBase64Golden.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void test1() throws Exception { byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); byte[] encoded = encoder.encode(src); Decoder decoder = Base64.getMimeDecoder(); byte[] decoded = decoder.decode(encoded); if (!Objects.deepEquals(src, decoded)) { throw new RuntimeException(); } }
Example 16
Source File: TestBase64Golden.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void test1() throws Exception { byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); byte[] encoded = encoder.encode(src); Decoder decoder = Base64.getMimeDecoder(); byte[] decoded = decoder.decode(encoded); if (!Objects.deepEquals(src, decoded)) { throw new RuntimeException(); } }
Example 17
Source File: TestBase64.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 18
Source File: TestBase64.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private static void testDecodeIgnoredAfterPadding() throws Throwable { for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) { byte[][] src = new byte[][] { "A".getBytes("ascii"), "AB".getBytes("ascii"), "ABC".getBytes("ascii"), "ABCD".getBytes("ascii"), "ABCDE".getBytes("ascii") }; Base64.Encoder encM = Base64.getMimeEncoder(); Base64.Decoder decM = Base64.getMimeDecoder(); Base64.Encoder enc = Base64.getEncoder(); Base64.Decoder dec = Base64.getDecoder(); for (int i = 0; i < src.length; i++) { // decode(byte[]) byte[] encoded = encM.encode(src[i]); encoded = Arrays.copyOf(encoded, encoded.length + 1); encoded[encoded.length - 1] = nonBase64; checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored"); byte[] decoded = new byte[src[i].length]; decM.decode(encoded, decoded); checkEqual(decoded, src[i], "Non-base64 char is not ignored"); try { dec.decode(encoded); throw new RuntimeException("No IAE for non-base64 char"); } catch (IllegalArgumentException iae) {} } } }
Example 19
Source File: Base64GetEncoderTest.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
public static void main(String args[]) throws Throwable { final Base64.Encoder encoder = Base64.getMimeEncoder(0, "$$$".getBytes(US_ASCII)); testEncodeToString(encoder); testWrapEncode1(encoder); testEncodeToStringWithLongInputData(encoder); testWrapEncode2(encoder); }
Example 20
Source File: Base64GetEncoderTest.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
public static void main(String args[]) throws Throwable { final Base64.Encoder encoder = Base64.getMimeEncoder(0, "$$$".getBytes(US_ASCII)); testEncodeToString(encoder); testWrapEncode1(encoder); testEncodeToStringWithLongInputData(encoder); testWrapEncode2(encoder); }