org.bouncycastle.crypto.digests.MD5Digest Java Examples

The following examples show how to use org.bouncycastle.crypto.digests.MD5Digest. 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: PBKDF2CipherProvider.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private Digest resolvePRF(final String prf) {
    if (StringUtils.isEmpty(prf)) {
        throw new IllegalArgumentException("Cannot resolve empty PRF");
    }
    String formattedPRF = prf.toLowerCase().replaceAll("[\\W]+", "");
    logger.debug("Resolved PRF {} to {}", prf, formattedPRF);
    switch (formattedPRF) {
        case "md5":
            return new MD5Digest();
        case "sha1":
            return new SHA1Digest();
        case "sha384":
            return new SHA384Digest();
        case "sha256":
            return new SHA256Digest();
        case "sha512":
            return new SHA512Digest();
        default:
            logger.warn("Could not resolve PRF {}. Using default PRF {} instead", prf, DEFAULT_PRF);
            return new SHA512Digest();
    }
}
 
Example #2
Source File: PBKDF2CipherProvider.java    From nifi with Apache License 2.0 6 votes vote down vote up
private Digest resolvePRF(final String prf) {
    if (StringUtils.isEmpty(prf)) {
        throw new IllegalArgumentException("Cannot resolve empty PRF");
    }
    String formattedPRF = prf.toLowerCase().replaceAll("[\\W]+", "");
    logger.debug("Resolved PRF {} to {}", prf, formattedPRF);
    switch (formattedPRF) {
        case "md5":
            return new MD5Digest();
        case "sha1":
            return new SHA1Digest();
        case "sha384":
            return new SHA384Digest();
        case "sha256":
            return new SHA256Digest();
        case "sha512":
            return new SHA512Digest();
        default:
            logger.warn("Could not resolve PRF {}. Using default PRF {} instead", prf, DEFAULT_PRF);
            return new SHA512Digest();
    }
}
 
Example #3
Source File: MD5Test.java    From java_security with MIT License 5 votes vote down vote up
public static void bcMD5()
{
	MD5Digest digest = new MD5Digest();
	digest.update(src.getBytes(),0,src.getBytes().length);
	byte[] md5Bytes = new byte[digest.getDigestSize()];
	digest.doFinal(md5Bytes, 0);
	System.out.println("bouncy castle MD5:" + org.bouncycastle.util.encoders.Hex.toHexString(md5Bytes));
	
}
 
Example #4
Source File: HMACTest.java    From java_security with MIT License 5 votes vote down vote up
public static void bcHmacMD5()
{
	HMac hmac = new HMac(new MD5Digest());
	// 必须是16进制的字符,长度必须是2的倍数
	hmac.init(new KeyParameter(org.bouncycastle.util.encoders.Hex.decode("123456789abcde")));
	hmac.update(src.getBytes(), 0, src.getBytes().length);
	
	// 执行摘要
	byte[] hmacMD5Bytes = new byte[hmac.getMacSize()];
	hmac.doFinal(hmacMD5Bytes, 0);
	System.out.println("bc hmacMD5:" + org.bouncycastle.util.encoders.Hex.toHexString(hmacMD5Bytes));
	
}
 
Example #5
Source File: BouncyCastleHasher.java    From hash-bench with MIT License 4 votes vote down vote up
public static final void register(final Map<String, Hasher> hashers) {
  hashers.put(BouncyCastleHasher.GOST,
          new BouncyCastleHasher(new GOST3411Digest()));
  hashers.put(BouncyCastleHasher.MD2,
          new BouncyCastleHasher(new MD2Digest()));
  hashers.put(BouncyCastleHasher.MD4,
          new BouncyCastleHasher(new MD4Digest()));
  hashers.put(BouncyCastleHasher.MD5,
          new BouncyCastleHasher(new MD5Digest()));
  hashers.put(BouncyCastleHasher.RIPEMD128,
          new BouncyCastleHasher(new RIPEMD128Digest()));
  hashers.put(BouncyCastleHasher.RIPEMD160,
          new BouncyCastleHasher(new RIPEMD160Digest()));
  hashers.put(BouncyCastleHasher.RIPEMD256,
          new BouncyCastleHasher(new RIPEMD256Digest()));
  hashers.put(BouncyCastleHasher.RIPEMD320,
          new BouncyCastleHasher(new RIPEMD320Digest()));
  hashers.put(BouncyCastleHasher.SHA1,
          new BouncyCastleHasher(new SHA1Digest()));
  hashers.put(BouncyCastleHasher.SHA224,
          new BouncyCastleHasher(new SHA224Digest()));
  hashers.put(BouncyCastleHasher.SHA256,
          new BouncyCastleHasher(new SHA256Digest()));
  hashers.put(BouncyCastleHasher.SHA3,
          new BouncyCastleHasher(new SHA3Digest()));
  hashers.put(BouncyCastleHasher.SHA384,
          new BouncyCastleHasher(new SHA384Digest()));
  hashers.put(BouncyCastleHasher.SHA512,
          new BouncyCastleHasher(new SHA512Digest()));
  hashers.put(BouncyCastleHasher.SHA512_T,
          new BouncyCastleHasher(new SHA512tDigest(7 * 8)));
  hashers.put(BouncyCastleHasher.SKEIN1024, new BouncyCastleHasher(
          new SkeinDigest(SkeinDigest.SKEIN_1024, Long.BYTES * 8)));
  hashers.put(BouncyCastleHasher.SKEIN256, new BouncyCastleHasher(
          new SkeinDigest(SkeinDigest.SKEIN_256, Long.BYTES * 8)));
  hashers.put(BouncyCastleHasher.SKEIN512, new BouncyCastleHasher(
          new SkeinDigest(SkeinDigest.SKEIN_512, Long.BYTES * 8)));
  hashers.put(BouncyCastleHasher.SM3,
          new BouncyCastleHasher(new SM3Digest()));
  hashers.put(BouncyCastleHasher.TIGER,
          new BouncyCastleHasher(new TigerDigest()));
  hashers.put(BouncyCastleHasher.WHIRLPOOL2,
          new BouncyCastleHasher(new WhirlpoolDigest()));
}