본문 바로가기

bouncy castle

[bouncy castle] hash md5

md5 hash example

public byte[] md5(byte[] text) {
    // create MD5 digest
    Digest digest = new MD5Digest();

    // get block size for output buffer
    int blockSize = digest.getDigestSize();
    byte[] buf = new byte[blockSize];

    digest.update(text, 0, text.length);
    digest.doFinal(buf, 0);
    return buf;
}

public void hash_md5_test_001() {
    byte[] text = "Hello world".getBytes(StandardCharsets.UTF_8);
    Hash hash = new Hash();
    byte[] ret = hash.md5(text);
    assertEquals("3E25960A79DBC69B674CD4EC67A72C62", toHex(ret));
}

 

소스코드 

https://github.com/coolbong/BouncyCastleExample/blob/master/src/main/java/io/github/coolbong/Hash.java