The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.security  [30 examples] > Message Digests  [2 examples]

e207. Creating a Keyed Digest Using MD5

A keyed digest is one in which a secret key is used to create a digest for a buffer of bytes. You can use different keys to create different digests for the same buffer of bytes.
    public static byte[] getKeyedDigest(byte[] buffer, byte[] key) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(buffer);
            return md5.digest(key);
        } catch (NoSuchAlgorithmException e) {
        }
        return null;
    }

 Related Examples
e206. Listing All Available Message Digest Algorithms

See also: Key Store    Permissions    Policy Files    Public and Private Keys    Signatures   


© 2002 Addison-Wesley.