The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.crypto  [14 examples] > MAC  [3 examples]

e468. Generating a Message Authentication Code (MAC) Key

For more information on a MAC, see RFC 2104. See also e467 Listing All Available Message Authentication Code (MAC) Key Generators.
    try {
        // Generate a key for the HMAC-MD5 keyed-hashing algorithm
        KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5");
        SecretKey key = keyGen.generateKey();
    
        // Generate a key for the HMAC-SHA1 keyed-hashing algorithm
        keyGen = KeyGenerator.getInstance("HmacSHA1");
        key = keyGen.generateKey();
    } catch (java.security.NoSuchAlgorithmException e) {
    }

 Related Examples
e467. Listing All Available Message Authentication Code (MAC) Key Generators
e469. Generating a Message Authentication Code (MAC)

See also: Encrypting and Decrypting    Key Agreement    Symmetric Keys   


© 2002 Addison-Wesley.