com.plumtree.openfoundation.security
Class XPAESCrypto

java.lang.Object
  extended by com.plumtree.openfoundation.security.XPAESCrypto
All Implemented Interfaces:
IXPCrypto

public class XPAESCrypto
extends java.lang.Object
implements IXPCrypto

XPAESCrypto implements AES 128-bit encryption for String values. For encryption, plaintext strings are converted to their UTF-8 byte representation first. These bytes are encrypted and then base64-encoded back into a String. Finally, an encryption marker is prepended to indicate the type of encryption used.

Author:
Joseph Chen

Field Summary
static int AES_BLOCK_SIZE
          Block size in bytes for both 256-bit and 128-bit AES encryption.
static char AES_ENCRYPTION_MARKER_128
          Encryption marker for Open Kernel 128-bit encrypted strings.
static int MAX_KEY_SIZE_128
          Maximum number of bytes for a 128-bit AES key.
 
Constructor Summary
XPAESCrypto(XPCryptoType cryptoType)
          Creates a new XPAESCrypto object.
 
Method Summary
 boolean CanDecrypt(java.lang.String toDecrypt)
          Can this provider decrypt this string?
 java.lang.String Decrypt(java.lang.String cipherText, byte[] key)
          Decrypts data which was encrypted using Encrypt.
 java.lang.String Decrypt(java.lang.String cipherText, java.lang.String password)
          Decrypts data which was encrypted using Encrypt.
 java.lang.String Encrypt(java.lang.String plainText, byte[] key)
          Encrypts data.
 java.lang.String Encrypt(java.lang.String plainText, java.lang.String password)
          Encrypts data.
 byte[] GenerateKey()
          Generate a key with default scenario, by allocating an array of the desired key size and add the size of the AES block and filling it with random bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AES_ENCRYPTION_MARKER_128

public static final char AES_ENCRYPTION_MARKER_128
Encryption marker for Open Kernel 128-bit encrypted strings.

See Also:
Constant Field Values

MAX_KEY_SIZE_128

public static final int MAX_KEY_SIZE_128
Maximum number of bytes for a 128-bit AES key.

See Also:
Constant Field Values

AES_BLOCK_SIZE

public static final int AES_BLOCK_SIZE
Block size in bytes for both 256-bit and 128-bit AES encryption.

See Also:
Constant Field Values
Constructor Detail

XPAESCrypto

public XPAESCrypto(XPCryptoType cryptoType)
Creates a new XPAESCrypto object.

Parameters:
cryptoType - The CryptoType must be XPCryptoType.AES_128.
Method Detail

Encrypt

public java.lang.String Encrypt(java.lang.String plainText,
                                java.lang.String password)
Description copied from interface: IXPCrypto
Encrypts data. Use Decrypt to decrypt the data.

Specified by:
Encrypt in interface IXPCrypto
Parameters:
plainText - the data to encrypt
password - a key generated from this password will be used to decrypt the data
Returns:
the encrypted data

Encrypt

public java.lang.String Encrypt(java.lang.String plainText,
                                byte[] key)
Description copied from interface: IXPCrypto
Encrypts data. Use Decrypt to decrypt the data.

Specified by:
Encrypt in interface IXPCrypto
Parameters:
plainText - the data to encrypt
key - the key to use to encrypt the data
Returns:
the encrypted data

Decrypt

public java.lang.String Decrypt(java.lang.String cipherText,
                                java.lang.String password)
Description copied from interface: IXPCrypto
Decrypts data which was encrypted using Encrypt.

Specified by:
Decrypt in interface IXPCrypto
Parameters:
cipherText - the data to decrypt
password - a key generated from this password will be used to decrypt the data
Returns:
the decrypted data

Decrypt

public java.lang.String Decrypt(java.lang.String cipherText,
                                byte[] key)
Description copied from interface: IXPCrypto
Decrypts data which was encrypted using Encrypt.

Specified by:
Decrypt in interface IXPCrypto
Parameters:
cipherText - the data to decrypt
key - the key to use to decrypt the data
Returns:
the decrypted data

CanDecrypt

public boolean CanDecrypt(java.lang.String toDecrypt)
Description copied from interface: IXPCrypto
Can this provider decrypt this string?

Specified by:
CanDecrypt in interface IXPCrypto
Parameters:
toDecrypt - an encrypted string
Returns:
true if this provider can decrypt the string

GenerateKey

public byte[] GenerateKey()
Generate a key with default scenario, by allocating an array of the desired key size and add the size of the AES block and filling it with random bytes.

Specified by:
GenerateKey in interface IXPCrypto
Returns:
the key


Copyright © 2002, 2003, 2004 Plumtree Software Inc. All Rights Reserved.