com.sun.slamd.scripting.mail
Class CRAMMD5Handler

java.lang.Object
  extended bycom.sun.slamd.scripting.mail.CRAMMD5Handler

public class CRAMMD5Handler
extends java.lang.Object

This class provides a set of methods that can be used in the process of authenticating to a server using CRAM-MD5 as defined in RFC 2195, which itself is based on HMAC as defined in RFC 2104.


Field Summary
static int BLOCK_LENGTH
          The block length in characters used in generating an HMAC-MD5 digest.
static byte IPAD_BYTE
          The inner pad byte, which will be XORed with the shared secret for the first digest.
static int MD5_DIGEST_LENGTH
          The number of bytes contained in an MD5 digest.
static byte OPAD_BYTE
          The outer pad byte, which will be XORed with the shared secret for the second digest.
 
Constructor Summary
CRAMMD5Handler()
          Creates a new instance of this CRAM-MD5 handler.
 
Method Summary
 java.lang.String generateCRAMMD5Response(java.lang.String username, java.lang.String password, java.lang.String challenge)
          Generates the CRAM-MD5 response that should be used for the provided information.
 byte[] generateHMACMD5(byte[] data, byte[] key)
          Generates an HMAC-MD5 response based on the provided key and data.
static void main(java.lang.String[] args)
          Provides a means of testing this CRAM-MD5 handler by generating a CRAM-MD5 response for the given information.
static void writeToHexString(byte[] byteArray, java.lang.StringBuffer buffer)
          Writes a hexadecimal representation of the contents of the provided byte array into the given string buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOCK_LENGTH

public static final int BLOCK_LENGTH
The block length in characters used in generating an HMAC-MD5 digest.

See Also:
Constant Field Values

MD5_DIGEST_LENGTH

public static final int MD5_DIGEST_LENGTH
The number of bytes contained in an MD5 digest.

See Also:
Constant Field Values

IPAD_BYTE

public static final byte IPAD_BYTE
The inner pad byte, which will be XORed with the shared secret for the first digest.

See Also:
Constant Field Values

OPAD_BYTE

public static final byte OPAD_BYTE
The outer pad byte, which will be XORed with the shared secret for the second digest.

See Also:
Constant Field Values
Constructor Detail

CRAMMD5Handler

public CRAMMD5Handler()
               throws java.security.NoSuchAlgorithmException
Creates a new instance of this CRAM-MD5 handler.

Throws:
java.security.NoSuchAlgorithmException - If a problem occurs while trying to initialize the MD5 digest handler.
Method Detail

main

public static void main(java.lang.String[] args)
Provides a means of testing this CRAM-MD5 handler by generating a CRAM-MD5 response for the given information. The data to use to generate the response must be provided as arguments and the response will be written to standard output.

Parameters:
args - The command line arguments provided to this program. There must be exactly three arguments, and they must be the username, password, and challenge (in that order).

generateCRAMMD5Response

public java.lang.String generateCRAMMD5Response(java.lang.String username,
                                                java.lang.String password,
                                                java.lang.String challenge)
Generates the CRAM-MD5 response that should be used for the provided information.

Parameters:
username - The username to use in the authentication process.
password - The password to use in the authentication process.
challenge - The challenge provided by the server to which authentication is to be performed.
Returns:
The string containing the CRAM-MD5 response.

generateHMACMD5

public byte[] generateHMACMD5(byte[] data,
                              byte[] key)
Generates an HMAC-MD5 response based on the provided key and data.

Parameters:
data - The plain-text data to include in the response.
key - The secret key to use in the response.
Returns:
A byte array containing the HMAC-MD5 response.

writeToHexString

public static void writeToHexString(byte[] byteArray,
                                    java.lang.StringBuffer buffer)
Writes a hexadecimal representation of the contents of the provided byte array into the given string buffer. All hexadecimal digits greater than nine will use the lowercase alphabetic representation.