@Override protected byte[] doDecoding(final byte[] bytes) { if (bytes == null) { return null; } return Base64.decodeBase64(bytes); }
/** * Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature. * * @param pArray * a byte array containing base64 character data * @return A BigInteger * @since 1.4 */ public static BigInteger decodeInteger(final byte[] pArray) { return new BigInteger(1, decodeBase64(pArray)); }
/** * Gets the public part of the RSA key that represents the server identity. */ public PublicKey getIdentity() throws GeneralSecurityException { if (identity==null) return null; byte[] image = Base64.decodeBase64(identity); return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(image)); } }
public SecretKey generalKey() { byte[] encodedKey = Base64.decodeBase64(secret); return new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); }
private Map<byte[], byte[]> convertBase64MapToBinaryMap(Map<String, String> base64Map) { Map<byte[], byte[]> binaryMap = new HashMap<>(); for (Map.Entry<String, String> entry : base64Map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); byte[] binaryKey = Base64.decodeBase64(key); byte[] binaryValue = Base64.decodeBase64(value); binaryMap.put(binaryKey, binaryValue); } return binaryMap; }
public X509EncodedKeySpec readKey() throws IOException { byte[] otherHalf = Base64.decodeBase64(readUTF()); // for historical reasons, we don't use readByteArray() return new X509EncodedKeySpec(otherHalf); }
public FixedAvroSerializer() throws IOException, NoSuchAlgorithmException { InputStream in = this.getClass().getClassLoader().getResourceAsStream("FixedAvroSerializer.config"); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { Schema schema = new Schema.Parser().parse(line); byte[] fp = SchemaNormalization.parsingFingerprint(FP_ALGO, schema); String fingerPrint = new String(Base64.decodeBase64(fp)); fingerprint2schemaMap.put(fingerPrint, schema); schema2fingerprintMap.put(schema, fingerPrint); } }
/** * CODEC-68: isBase64 throws ArrayIndexOutOfBoundsException on some * non-BASE64 bytes */ @Test public void testCodec68() { final byte[] x = new byte[] { 'n', 'A', '=', '=', (byte) 0x9c }; Base64.decodeBase64(x); }
@Test public void testDecodePadOnly() { assertEquals(0, Base64.decodeBase64("====".getBytes(CHARSET_UTF8)).length); assertEquals("", new String(Base64.decodeBase64("====".getBytes(CHARSET_UTF8)))); // Test truncated padding assertEquals(0, Base64.decodeBase64("===".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("==".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("=".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("".getBytes(CHARSET_UTF8)).length); }
@Test public void testDecodePadOnlyChunked() { assertEquals(0, Base64.decodeBase64("====\n".getBytes(CHARSET_UTF8)).length); assertEquals("", new String(Base64.decodeBase64("====\n".getBytes(CHARSET_UTF8)))); // Test truncated padding assertEquals(0, Base64.decodeBase64("===\n".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("==\n".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("=\n".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("\n".getBytes(CHARSET_UTF8)).length); }
@Test public void testKnownDecodings() { assertEquals("The quick brown fox jumped over the lazy dogs.", new String(Base64.decodeBase64( "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes(CHARSET_UTF8)))); assertEquals("It was the best of times, it was the worst of times.", new String(Base64.decodeBase64( "SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==".getBytes(CHARSET_UTF8)))); assertEquals("http://jakarta.apache.org/commmons", new String( Base64.decodeBase64("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==".getBytes(CHARSET_UTF8)))); assertEquals("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz", new String(Base64.decodeBase64( "QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==".getBytes(CHARSET_UTF8)))); assertEquals("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }", new String(Base64.decodeBase64("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=".getBytes(CHARSET_UTF8)))); assertEquals("xyzzy!", new String(Base64.decodeBase64("eHl6enkh".getBytes(CHARSET_UTF8)))); }
/** * Tests conditional branches for "marker1" test. */ @Test public void testDecodePadMarkerIndex3() { assertEquals("AA", new String(Base64.decodeBase64("QUE=".getBytes(CHARSET_UTF8)))); assertEquals("AAA", new String(Base64.decodeBase64("QUFB".getBytes(CHARSET_UTF8)))); }
@Test public void testIgnoringNonBase64InDecode() throws Exception { assertEquals("The quick brown fox jumped over the lazy dogs.", new String(Base64.decodeBase64( "VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n\r\t%#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" .getBytes(CHARSET_UTF8)))); }
/** * Tests conditional true branch for "marker0" test. */ @Test public void testDecodePadMarkerIndex2() { assertEquals("A", new String(Base64.decodeBase64("QQ==".getBytes(CHARSET_UTF8)))); }
@Test public void testPairs() { assertEquals("AAA=", new String(Base64.encodeBase64(new byte[] { 0, 0 }))); for (int i = -128; i <= 127; i++) { final byte test[] = { (byte) i, (byte) i }; assertTrue(Arrays.equals(test, Base64.decodeBase64(Base64.encodeBase64(test)))); } }
@Test public void testObjectEncodeWithValidParameter() throws Exception { final String original = "Hello World!"; final Object origObj = original.getBytes(CHARSET_UTF8); final Base64 b64 = new Base64(); final Object oEncoded = b64.encode(origObj); final byte[] bArray = Base64.decodeBase64((byte[]) oEncoded); final String dest = new String(bArray); assertEquals("dest string does not equal original", original, dest); }
private void testEncodeDecode(final String plainText) { final String encodedText = Base64.encodeBase64String(StringUtils.getBytesUtf8(plainText)); final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64(encodedText)); assertEquals(plainText, decodedText); }
private void testDecodeEncode(final String encodedText) { final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64(encodedText)); final String encodedText2 = Base64.encodeBase64String(StringUtils.getBytesUtf8(decodedText)); assertEquals(encodedText, encodedText2); }
@Test public void testEncodeDecodeRandom() { for (int i = 1; i < 5; i++) { final byte[] data = new byte[this.getRandom().nextInt(10000) + 1]; this.getRandom().nextBytes(data); final byte[] enc = Base64.encodeBase64(data); assertTrue(Base64.isBase64(enc)); final byte[] data2 = Base64.decodeBase64(enc); assertTrue(Arrays.equals(data, data2)); } }
@Test public void testEncodeDecodeSmall() { for (int i = 0; i < 12; i++) { final byte[] data = new byte[i]; this.getRandom().nextBytes(data); final byte[] enc = Base64.encodeBase64(data); assertTrue("\"" + new String(enc) + "\" is Base64 data.", Base64.isBase64(enc)); final byte[] data2 = Base64.decodeBase64(enc); assertTrue(toString(data) + " equals " + toString(data2), Arrays.equals(data, data2)); } }