org.norther.tammi.core.security
Class DefaultMessageDigestFactory

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.base.DefaultObjectFactory<MessageDigest>
          extended by org.norther.tammi.core.security.DefaultMessageDigestFactory
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, ObjectFactory<MessageDigest>, MessageDigestFactory

public class DefaultMessageDigestFactory
extends DefaultObjectFactory<MessageDigest>
implements MessageDigestFactory

A default implementation of MessageDigestFactory.

Version:
$Id: DefaultMessageDigestFactory.java,v 1.7 2009/09/28 15:08:43 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultMessageDigestFactory()
          Constructs a new factory.
 
Method Summary
 String decodeBase64(String string)
          Decodes a BASE64 string applying the UTF-8 encoding.
 String decodeBase64(String string, String encoding)
          Decodes a BASE64 string applying the specified encoding.
 String digest(String algorithm, String string)
          Computes a hash for the given string by applying platform's default encoding.
 String digest(String algorithm, String string, String encoding)
          Computes a hash for the given string applying the specified encoding.
 String digest(String algorithm, String salt, String string, String encoding)
          Computes a hash for the given string using the given salt and applying the specified encoding.
 String encodeBase64(String string)
          Encodes a BASE64 string applying the UTF-8 encoding.
 String encodeBase64(String string, String encoding)
          Encodes a BASE64 string applying the specified encoding.
 String generate(String algorithm)
          Generates a secret key and returns its string representation.
 MessageDigest getInstance(String className, ObjectName loader, Object[] params, String[] signature)
          Gets an instance of a named class using a specified class loader.
 boolean isLoaderSupported(String className)
          Checks if specified class loaders are supported for a named class.
 
Methods inherited from class org.norther.tammi.core.base.DefaultObjectFactory
getInstance, getInstance, getInstance
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.base.ObjectFactory
getInstance, getInstance, getInstance
 

Constructor Detail

DefaultMessageDigestFactory

public DefaultMessageDigestFactory()
Constructs a new factory.

Method Detail

digest

public String digest(String algorithm,
                     String string)
              throws NoSuchAlgorithmException
Description copied from interface: MessageDigestFactory
Computes a hash for the given string by applying platform's default encoding.

Specified by:
digest in interface MessageDigestFactory
Parameters:
algorithm - the digest algorithm.
string - the string to use.
Returns:
the BASE64 or MD5 encoded hash.
Throws:
NoSuchAlgorithmException - if the algorithm is unknown.

digest

public String digest(String algorithm,
                     String string,
                     String encoding)
              throws NoSuchAlgorithmException
Description copied from interface: MessageDigestFactory
Computes a hash for the given string applying the specified encoding.

Specified by:
digest in interface MessageDigestFactory
Parameters:
algorithm - the digest algorithm.
string - the string to use.
encoding - the character encoding.
Returns:
the BASE64 or MD5 encoded hash.
Throws:
NoSuchAlgorithmException - if the algorithm is unknown.

digest

public String digest(String algorithm,
                     String salt,
                     String string,
                     String encoding)
              throws NoSuchAlgorithmException
Description copied from interface: MessageDigestFactory
Computes a hash for the given string using the given salt and applying the specified encoding.

Specified by:
digest in interface MessageDigestFactory
Parameters:
algorithm - the digest algorithm.
salt - the salt to use.
string - the string to use.
encoding - the character encoding.
Returns:
the BASE64 or MD5 encoded hash.
Throws:
NoSuchAlgorithmException - if the algorithm is unknown.

generate

public String generate(String algorithm)
                throws NoSuchAlgorithmException
Description copied from interface: MessageDigestFactory
Generates a secret key and returns its string representation.

Specified by:
generate in interface MessageDigestFactory
Parameters:
algorithm - the secret algorithm.
Returns:
the BASE64 encoded key.
Throws:
NoSuchAlgorithmException - if the algorithm is unknown.

encodeBase64

public String encodeBase64(String string)
Description copied from interface: MessageDigestFactory
Encodes a BASE64 string applying the UTF-8 encoding.

Specified by:
encodeBase64 in interface MessageDigestFactory
Parameters:
string - the string to encode.
Returns:
the encoded string.

encodeBase64

public String encodeBase64(String string,
                           String encoding)
Description copied from interface: MessageDigestFactory
Encodes a BASE64 string applying the specified encoding.

Specified by:
encodeBase64 in interface MessageDigestFactory
Parameters:
string - the string to encode.
encoding - the character encoding.
Returns:
the encoded string.

decodeBase64

public String decodeBase64(String string)
Description copied from interface: MessageDigestFactory
Decodes a BASE64 string applying the UTF-8 encoding.

Specified by:
decodeBase64 in interface MessageDigestFactory
Parameters:
string - the string to decode.
Returns:
the decoded string.

decodeBase64

public String decodeBase64(String string,
                           String encoding)
Description copied from interface: MessageDigestFactory
Decodes a BASE64 string applying the specified encoding.

Specified by:
decodeBase64 in interface MessageDigestFactory
Parameters:
string - the string to decode.
encoding - the character encoding.
Returns:
the decoded string.

getInstance

public MessageDigest getInstance(String className,
                                 ObjectName loader,
                                 Object[] params,
                                 String[] signature)
                          throws ConstructionException
Description copied from interface: ObjectFactory
Gets an instance of a named class using a specified class loader. Parameters for its constructor are given as an array of objects, primitive types must be wrapped with a corresponding class.

Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.

Specified by:
getInstance in interface ObjectFactory<MessageDigest>
Overrides:
getInstance in class DefaultObjectFactory<MessageDigest>
Parameters:
className - the name of the class.
loader - the class loader.
params - an array containing the parameters of the constructor.
signature - an array containing the signature of the constructor.
Returns:
the instance.
Throws:
ConstructionException - if construction fails.

isLoaderSupported

public boolean isLoaderSupported(String className)
Description copied from interface: ObjectFactory
Checks if specified class loaders are supported for a named class.

Specified by:
isLoaderSupported in interface ObjectFactory<MessageDigest>
Overrides:
isLoaderSupported in class DefaultObjectFactory<MessageDigest>
Parameters:
className - the name of the class.
Returns:
true if class loaders are supported, false otherwise.


Copyright © 2004 The Norther Organization. All rights reserved.