uk.org.ogsadai.common.rolemap
Class Cryptography

java.lang.Object
  |
  +--uk.org.ogsadai.common.rolemap.Cryptography

public class Cryptography
extends java.lang.Object

A collection of methods related to encrypting and decrypting strings, which can be used by the SimpleFileWithEncryptedPasswordsRoleMapper to encrypt and decrypt database passwords.

Author:
The OGSA-DAI Project Team

Constructor Summary
Cryptography()
           
 
Method Summary
static java.lang.String getPassword()
          Returns the value of the ogsadai.password system property, or throws an exception if it is not set.
static java.lang.String scramble(java.lang.String password, byte[] plainText)
          Encrypts an array of bytes, using a given password, and returns the encrypted bytes as a Base-64 encoded string.
static java.lang.String scramble(java.lang.String password, java.lang.String plainText)
          Encrypts a string, using a given password, and returns the encrypted text as a Base-64 encoded string.
static java.lang.String unscramble(java.lang.String scrambled)
          Unencrypts a Base-64 encoded string, using the value of the ogsadai.password system property as a password, and returns the unencrypted string.
static java.lang.String unscramble(java.lang.String password, byte[] scrambled)
          Unencrypts an array of Base-64 encoded bytes, using a given password, and returns the unencrypted bytes as a string.
static java.lang.String unscramble(java.lang.String password, java.lang.String scrambled)
          Unencrypts a Base-64 encoded string, using a given password, and returns the unencrypted string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cryptography

public Cryptography()
Method Detail

getPassword

public static java.lang.String getPassword()
                                    throws CommonUserException
Returns the value of the ogsadai.password system property, or throws an exception if it is not set.

Returns:
the value of the password property
Throws:
CommonSystemException - if the property is not set
CommonUserException

scramble

public static java.lang.String scramble(java.lang.String password,
                                        byte[] plainText)
                                 throws CommonSystemException
Encrypts an array of bytes, using a given password, and returns the encrypted bytes as a Base-64 encoded string.

Parameters:
password - the password to use as a key
plainText - the bytes to encrypt
Returns:
the encrypted and Base-64 encoded string
Throws:
CommonSystemException - if a problem occurred

scramble

public static java.lang.String scramble(java.lang.String password,
                                        java.lang.String plainText)
                                 throws CommonSystemException
Encrypts a string, using a given password, and returns the encrypted text as a Base-64 encoded string.

Parameters:
password - the password to use as a key
plainText - the string to encrypt
Returns:
the encrypted and Base-64 encoded string
Throws:
CommonSystemException - if a problem occurred

unscramble

public static java.lang.String unscramble(java.lang.String password,
                                          byte[] scrambled)
                                   throws CommonSystemException
Unencrypts an array of Base-64 encoded bytes, using a given password, and returns the unencrypted bytes as a string.

Parameters:
password - the password to use as a key
scrambled - the bytes to Base-64 decode and decrypt
Returns:
the decrypted string
Throws:
CommonSystemException - if a problem occurred

unscramble

public static java.lang.String unscramble(java.lang.String password,
                                          java.lang.String scrambled)
                                   throws CommonSystemException
Unencrypts a Base-64 encoded string, using a given password, and returns the unencrypted string.

Parameters:
password - the password to use as a key
scrambled - the string to Base-64 decode and decrypt
Returns:
the decrypted string
Throws:
CommonSystemException - if a problem occurred

unscramble

public static java.lang.String unscramble(java.lang.String scrambled)
                                   throws CommonSystemException,
                                          CommonUserException
Unencrypts a Base-64 encoded string, using the value of the ogsadai.password system property as a password, and returns the unencrypted string.

Parameters:
scrambled - the string to Base-64 decode and decrypt
Returns:
the decrypted string
Throws:
CommonSystemException - if a problem occurred
CommonUserException