org.apache.commons.codec.binary.Base64.decodeBase64()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中org.apache.commons.codec.binary.Base64.decodeBase64()方法的一些代码示例,展示了Base64.decodeBase64()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.decodeBase64()方法的具体详情如下:
包路径:org.apache.commons.codec.binary.Base64
类名称:Base64
方法名:decodeBase64

Base64.decodeBase64介绍

[英]Decodes a Base64 String into octets
[中]将Base64字符串解码为八位字节

代码示例

代码示例来源:origin: commons-codec/commons-codec

@Override
protected byte[] doDecoding(final byte[] bytes) {
  if (bytes == null) {
    return null;
  }
  return Base64.decodeBase64(bytes);
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * 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));
}

代码示例来源:origin: jenkinsci/jenkins

/**
   * 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));
  }
}

代码示例来源:origin: hs-web/hsweb-framework

public SecretKey generalKey() {
  byte[] encodedKey = Base64.decodeBase64(secret);
  return new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
}

代码示例来源:origin: apache/storm

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;
}

代码示例来源:origin: jenkinsci/jenkins

public X509EncodedKeySpec readKey() throws IOException {
  byte[] otherHalf = Base64.decodeBase64(readUTF()); // for historical reasons, we don't use readByteArray()
  return new X509EncodedKeySpec(otherHalf);
}

代码示例来源:origin: apache/storm

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);
  }
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * 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);
}

代码示例来源:origin: commons-codec/commons-codec

@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);
}

代码示例来源:origin: commons-codec/commons-codec

@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);
}

代码示例来源:origin: commons-codec/commons-codec

@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))));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * 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))));
}

代码示例来源:origin: commons-codec/commons-codec

@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))));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Tests conditional true branch for "marker0" test.
 */
@Test
public void testDecodePadMarkerIndex2() {
  assertEquals("A", new String(Base64.decodeBase64("QQ==".getBytes(CHARSET_UTF8))));
}

代码示例来源:origin: commons-codec/commons-codec

@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))));
  }
}

代码示例来源:origin: commons-codec/commons-codec

@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);
}

代码示例来源:origin: commons-codec/commons-codec

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);
}

代码示例来源:origin: commons-codec/commons-codec

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);
}

代码示例来源:origin: commons-codec/commons-codec

@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));
  }
}

代码示例来源:origin: commons-codec/commons-codec

@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));
  }
}

相关文章