com.arsdigita.kernel.security
Class Crypto

java.lang.Object
  extended bycom.arsdigita.kernel.security.Crypto

public class Crypto
extends Object

Provides cryptographic functions and stores the server's secret key.

Since:
ACS 4.5
Author:
Sameer Ajmani

Field Summary
static String CHARACTER_ENCODING
           
static String versionId
           
 
Constructor Summary
Crypto()
           
 
Method Summary
static String decrypt(String encrypted, char[] password)
          Decrypts a string with a key derived from a password.
static String encrypt(String decrypted, char[] password)
          Encrypts a string with a key derived from a password.
static SecureRandom getRandom()
          Returns a secure random number generator.
static void main(String[] args)
          Benchmarks password-based encryption and decryption.
static MessageDigest newDigester()
          Creates a new message digest (hash) calculator.
static javax.crypto.Mac newMac()
          Creates a new Message Authentication Code (MAC) calculator that uses the server's secret key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values

CHARACTER_ENCODING

public static final String CHARACTER_ENCODING
See Also:
Constant Field Values
Constructor Detail

Crypto

public Crypto()
Method Detail

newMac

public static javax.crypto.Mac newMac()
                               throws GeneralSecurityException
Creates a new Message Authentication Code (MAC) calculator that uses the server's secret key.

Returns:
a new Mac object.
Throws:
GeneralSecurityException - if an error occurs.

newDigester

public static MessageDigest newDigester()
                                 throws GeneralSecurityException
Creates a new message digest (hash) calculator.

Returns:
a new MessageDigest object.
Throws:
GeneralSecurityException - if an error occurs.

getRandom

public static SecureRandom getRandom()
                              throws GeneralSecurityException
Returns a secure random number generator.

Returns:
a SecureRandom number generator.
Throws:
GeneralSecurityException - if an error occurs.

encrypt

public static String encrypt(String decrypted,
                             char[] password)
                      throws GeneralSecurityException
Encrypts a string with a key derived from a password. Output is BASE64Encode(salt) + ":" + BASE64Encode(encrypt(UTF8Encode(cleartext.length() + ":" + cleartext))).

Parameters:
decrypted - the string to encrypt
password - the password from which to create an encryption key
Returns:
the encrypted string.
Throws:
GeneralSecurityException - if encryption fails.

decrypt

public static String decrypt(String encrypted,
                             char[] password)
                      throws GeneralSecurityException
Decrypts a string with a key derived from a password.

Parameters:
encrypted - the string to decrypt
password - the password from which to create an decryption key
Returns:
the decrypted string
Throws:
IllegalArgumentException - if the given string is not legal output of encrypt().
InvalidKeyException - if the decrypted text does not pass validation.
GeneralSecurityException - if decryption fails otherwise.

main

public static void main(String[] args)
                 throws GeneralSecurityException
Benchmarks password-based encryption and decryption.

Throws:
GeneralSecurityException


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC