com.noelios.restlet.util
Class SecurityUtils

java.lang.Object
  extended by com.noelios.restlet.util.SecurityUtils

public class SecurityUtils
extends java.lang.Object

Security data manipulation utilities.

Author:
Jerome Louvel

Constructor Summary
SecurityUtils()
           
 
Method Summary
static java.lang.String makeNonce(java.lang.String secretKey)
          Generates a nonce as recommended in section 3.2.1 of RFC-2617, but without the ETag field.
static byte[] toHMac(java.lang.String source, java.lang.String secretKey)
          Converts a source string to its HMAC/SHA-1 value.
static java.lang.String toMd5(java.lang.String target)
          Returns the MD5 digest of the target string.
static java.lang.String toMd5(java.lang.String target, java.lang.String charsetName)
          Returns the MD5 digest of target string.
static java.lang.String toSha1(java.lang.String target)
          Returns the SHA1 digest of the target string.
static java.lang.String toSha1(java.lang.String target, java.lang.String charsetName)
          Returns the SHA1 digest of target string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecurityUtils

public SecurityUtils()
Method Detail

makeNonce

public static java.lang.String makeNonce(java.lang.String secretKey)
Generates a nonce as recommended in section 3.2.1 of RFC-2617, but without the ETag field. The format is:
 Base64.encodeBytes(currentTimeMS + ":"
         + md5String(currentTimeMS + ":" + secretKey))
 

Parameters:
secretKey - a secret value known only to the creator of the nonce. It's inserted into the nonce, and can be used later to validate the nonce.

toHMac

public static byte[] toHMac(java.lang.String source,
                            java.lang.String secretKey)
Converts a source string to its HMAC/SHA-1 value.

Parameters:
source - The source string to convert.
secretKey - The secret key to use for conversion.
Returns:
The HMac value of the source string.

toMd5

public static java.lang.String toMd5(java.lang.String target)
Returns the MD5 digest of the target string. Target is decoded to bytes using the US-ASCII charset. The returned hexadecimal String always contains 32 lowercase alphanumeric characters. For example, if target is "HelloWorld", this method returns "68e109f0f40ca72a15e05cc22786f8e6".

Parameters:
target - The string to encode.
Returns:
The MD5 digest of the target string.

toMd5

public static java.lang.String toMd5(java.lang.String target,
                                     java.lang.String charsetName)
                              throws java.io.UnsupportedEncodingException
Returns the MD5 digest of target string. Target is decoded to bytes using the named charset. The returned hexadecimal String always contains 32 lowercase alphanumeric characters. For example, if target is "HelloWorld", this method returns "68e109f0f40ca72a15e05cc22786f8e6".

Parameters:
target - The string to encode.
charsetName - The character set.
Returns:
The MD5 digest of the target string.
Throws:
java.io.UnsupportedEncodingException

toSha1

public static java.lang.String toSha1(java.lang.String target)
Returns the SHA1 digest of the target string. Target is decoded to bytes using the US-ASCII charset.

Parameters:
target - The string to encode.
Returns:
The MD5 digest of the target string.

toSha1

public static java.lang.String toSha1(java.lang.String target,
                                      java.lang.String charsetName)
                               throws java.io.UnsupportedEncodingException
Returns the SHA1 digest of target string. Target is decoded to bytes using the named charset.

Parameters:
target - The string to encode.
charsetName - The character set.
Returns:
The SHA1 digest of the target string.
Throws:
java.io.UnsupportedEncodingException


Copyright © 2005-2008 Noelios Technologies.