maspack.fileutil
Class AESCrypter

java.lang.Object
  extended by maspack.fileutil.AESCrypter
All Implemented Interfaces:
Crypter
Direct Known Subclasses:
PasswordCryptor

public class AESCrypter
extends java.lang.Object
implements Crypter

A password encryption scheme that uses either a 128-bit,192-bit or 256-bit AES algorithm. To enable the 256-bit mode, you must install the JCE Unlimited Strength policy files: "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files"

Author:
"Antonio Sanchez" Creation date: 24 Oct 2012

Nested Class Summary
static class AESCrypter.KeySize
           
 
Field Summary
static AESCrypter.KeySize AES128
           
static AESCrypter.KeySize AES192
           
static AESCrypter.KeySize AES256
           
 
Constructor Summary
AESCrypter()
           
AESCrypter(byte[] key)
           
AESCrypter(java.lang.String hexKey)
           
 
Method Summary
 byte[] decrypt(byte[] data)
           
 java.lang.String decrypt(java.lang.String str)
           
 byte[] encrypt(byte[] data)
           
 java.lang.String encrypt(java.lang.String str)
           
static byte[] generateKeyFromPassphrase(java.lang.String passphrase, AESCrypter.KeySize keySize)
           
 AESCrypter.KeySize getKeySize()
           
 void setKey(byte[] key)
           
 void setKey(java.lang.String hexKey)
           
 void setKeyFromPassphrase(java.lang.String passphrase)
           
 boolean setKeySize(AESCrypter.KeySize keySize)
          Sets the key size, in number of bytes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AES256

public static final AESCrypter.KeySize AES256

AES192

public static final AESCrypter.KeySize AES192

AES128

public static final AESCrypter.KeySize AES128
Constructor Detail

AESCrypter

public AESCrypter()

AESCrypter

public AESCrypter(java.lang.String hexKey)
           throws java.lang.Exception
Throws:
java.lang.Exception

AESCrypter

public AESCrypter(byte[] key)
           throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

setKeySize

public boolean setKeySize(AESCrypter.KeySize keySize)
Sets the key size, in number of bytes

Parameters:
keySize - either 16 or 32
Returns:
false if the method did not succeed

getKeySize

public AESCrypter.KeySize getKeySize()

setKey

public void setKey(byte[] key)
            throws java.lang.Exception
Throws:
java.lang.Exception

setKey

public void setKey(java.lang.String hexKey)
            throws java.lang.Exception
Throws:
java.lang.Exception

setKeyFromPassphrase

public void setKeyFromPassphrase(java.lang.String passphrase)
                          throws java.lang.Exception
Throws:
java.lang.Exception

generateKeyFromPassphrase

public static byte[] generateKeyFromPassphrase(java.lang.String passphrase,
                                               AESCrypter.KeySize keySize)

encrypt

public java.lang.String encrypt(java.lang.String str)
                         throws java.lang.Exception
Specified by:
encrypt in interface Crypter
Throws:
java.lang.Exception

decrypt

public java.lang.String decrypt(java.lang.String str)
                         throws java.lang.Exception
Specified by:
decrypt in interface Crypter
Throws:
java.lang.Exception

encrypt

public byte[] encrypt(byte[] data)
               throws java.lang.Exception
Specified by:
encrypt in interface Crypter
Throws:
java.lang.Exception

decrypt

public byte[] decrypt(byte[] data)
               throws java.lang.Exception
Specified by:
decrypt in interface Crypter
Throws:
java.lang.Exception