com.openexchange.mail.utils
Class MailPasswordUtil

java.lang.Object
  extended by com.openexchange.mail.utils.MailPasswordUtil

public final class MailPasswordUtil
extends java.lang.Object

MailPasswordUtil - Utility class to encrypt/decrypt passwords with a key aka password based encryption (PBE).

PBE is a form of symmetric encryption where the same key or password is used to encrypt and decrypt a string.

Author:
Thorben Betten

Constructor Summary
MailPasswordUtil()
           
 
Method Summary
static java.lang.String decrypt(java.lang.String encryptedPassword, java.security.Key key)
          Decrypts specified encrypted password with given key.
static java.lang.String decrypt(java.lang.String encryptedPassword, java.lang.String key)
          Decrypts specified encrypted password with given key.
static java.lang.String encrypt(java.lang.String password, java.security.Key key)
          Encrypts specified password with given key.
static java.lang.String encrypt(java.lang.String password, java.lang.String key)
          Encrypts specified password with given key.
static java.security.Key generateRandomKey()
          Create a key for use in the cipher code
static java.security.Key generateSecretKey(java.lang.String key)
          Generates a secret key from specified key string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailPasswordUtil

public MailPasswordUtil()
Method Detail

encrypt

public static java.lang.String encrypt(java.lang.String password,
                                       java.lang.String key)
                                throws java.security.GeneralSecurityException
Encrypts specified password with given key.

Parameters:
password - The password
key - The key
Returns:
The encrypted password as Base64 encoded string
Throws:
java.security.GeneralSecurityException - If password encryption fails

decrypt

public static java.lang.String decrypt(java.lang.String encryptedPassword,
                                       java.lang.String key)
                                throws java.security.GeneralSecurityException
Decrypts specified encrypted password with given key.

Parameters:
encryptedPassword - The Base64 encoded encrypted password
key - The key
Returns:
The decrypted password
Throws:
java.security.GeneralSecurityException - If password decryption fails

encrypt

public static java.lang.String encrypt(java.lang.String password,
                                       java.security.Key key)
                                throws java.security.GeneralSecurityException
Encrypts specified password with given key.

Parameters:
password - The password to encrypt
key - The key
Returns:
The encrypted password as Base64 encoded string
Throws:
java.security.GeneralSecurityException - If password encryption fails

decrypt

public static java.lang.String decrypt(java.lang.String encryptedPassword,
                                       java.security.Key key)
                                throws java.security.GeneralSecurityException
Decrypts specified encrypted password with given key.

Parameters:
encryptedPassword - The Base64 encoded encrypted password
key - The key
Returns:
The decrypted password
Throws:
java.security.GeneralSecurityException - If password decryption fails

generateRandomKey

public static java.security.Key generateRandomKey()
                                           throws java.security.NoSuchAlgorithmException
Create a key for use in the cipher code

Throws:
java.security.NoSuchAlgorithmException

generateSecretKey

public static java.security.Key generateSecretKey(java.lang.String key)
                                           throws java.security.GeneralSecurityException
Generates a secret key from specified key string.

Parameters:
key - The key string
Returns:
A secret key generated from specified key string
Throws:
java.security.GeneralSecurityException - If generating secret key fails