Use bouncy castle MD5 Digest - Java Security

Java examples for Security:MD5

Description

Use bouncy castle MD5 Digest

Demo Code

import org.bouncycastle.crypto.digests.MD5Digest;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Hex;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.Security;

public class hash_md5 {

    public static void main(String[] args) throws NoSuchAlgorithmException,
            UnsupportedEncodingException {

        Security.addProvider(new BouncyCastleProvider());

        byte[] trial = "trial".getBytes();

        // TODO Auto-generated method stub
        MD5Digest examplemd5 = new MD5Digest();
        examplemd5.update(trial, 0, trial.length);

        byte[] digested = new byte[examplemd5.getDigestSize()];
        examplemd5.doFinal(digested, 0);

        System.out.println("Input (hex): " + new String(Hex.encode(trial)));
        System.out.println("Output (hex): "
                + new String(Hex.encode(digested)));

    }/*from w ww .ja va 2  s. c  o  m*/

}

Related Tutorials