|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.ssl.OpenSSL
public class OpenSSL
Class for encrypting or decrypting data with a password (PBE - password based encryption). Compatible with "openssl enc" unix utility. An OpenSSL compatible cipher name must be specified along with the password (try "man enc" on a unix box to see what's possible). Some examples:
// Encrypt! byte[] encryptedData = OpenSSL.encrypt( "des3", password, data );If you want to specify a raw key and iv directly (without using PBE), use the methods that take byte[] key, byte[] iv. Those byte[] arrays can be the raw binary, or they can be ascii (hex representation: '0' - 'F'). If you want to use PBE to derive the key and iv, then use the methods that take char[] password. This class is able to decrypt files encrypted with "openssl" unix utility. The "openssl" unix utility is able to decrypt files encrypted by this class. This class is also able to encrypt and decrypt its own files.
Nested Class Summary | |
---|---|
static class |
OpenSSL.CipherInfo
|
Constructor Summary | |
---|---|
OpenSSL()
|
Method Summary | |
---|---|
static byte[] |
decrypt(String cipher,
byte[] key,
byte[] iv,
byte[] encrypted)
|
static InputStream |
decrypt(String cipher,
byte[] key,
byte[] iv,
InputStream encrypted)
|
static byte[] |
decrypt(String cipher,
char[] pwd,
byte[] encrypted)
Decrypts data using a password and an OpenSSL compatible cipher name. |
static InputStream |
decrypt(String cipher,
char[] pwd,
InputStream encrypted)
Decrypts data using a password and an OpenSSL compatible cipher name. |
static DerivedKey |
deriveKey(char[] password,
byte[] salt,
int keySize,
boolean des2)
|
static DerivedKey |
deriveKey(char[] password,
byte[] salt,
int keySize,
int ivSize,
boolean des2)
|
static byte[] |
encrypt(String cipher,
byte[] key,
byte[] iv,
byte[] data)
|
static byte[] |
encrypt(String cipher,
byte[] key,
byte[] iv,
byte[] data,
boolean toBase64)
|
static InputStream |
encrypt(String cipher,
byte[] key,
byte[] iv,
InputStream data)
|
static InputStream |
encrypt(String cipher,
byte[] key,
byte[] iv,
InputStream data,
boolean toBase64)
|
static byte[] |
encrypt(String cipher,
char[] pwd,
byte[] data)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static byte[] |
encrypt(String cipher,
char[] pwd,
byte[] data,
boolean toBase64)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static byte[] |
encrypt(String cipher,
char[] pwd,
byte[] data,
boolean toBase64,
boolean useSalt)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static InputStream |
encrypt(String cipher,
char[] pwd,
InputStream data)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static InputStream |
encrypt(String cipher,
char[] pwd,
InputStream data,
boolean toBase64)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static InputStream |
encrypt(String cipher,
char[] pwd,
InputStream data,
boolean toBase64,
boolean useSalt)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static OpenSSL.CipherInfo |
lookup(String openSSLCipher)
Converts the way OpenSSL names its ciphers into a Java-friendly naming. |
static void |
main(String[] args)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public OpenSSL()
Method Detail |
---|
public static byte[] decrypt(String cipher, char[] pwd, byte[] encrypted) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE decryptionencrypted
- byte array to decrypt. Can be raw, or base64.
IOException
- problems with encrypted bytes (unlikely!)
GeneralSecurityException
- problems decryptingpublic static InputStream decrypt(String cipher, char[] pwd, InputStream encrypted) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE decryptionencrypted
- InputStream to decrypt. Can be raw, or base64.
IOException
- problems with InputStream
GeneralSecurityException
- problems decryptingpublic static byte[] encrypt(String cipher, char[] pwd, byte[] data) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE encryptiondata
- byte array to encrypt
IOException
- problems with the data byte array
GeneralSecurityException
- problems encryptingpublic static InputStream encrypt(String cipher, char[] pwd, InputStream data) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE encryptiondata
- InputStream to encrypt
IOException
- problems with the data InputStream
GeneralSecurityException
- problems encryptingpublic static byte[] encrypt(String cipher, char[] pwd, byte[] data, boolean toBase64) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE encryptiondata
- byte array to encrypttoBase64
- true if resulting InputStream should contain base64,
IOException
- problems with the data byte array
GeneralSecurityException
- problems encryptingpublic static InputStream encrypt(String cipher, char[] pwd, InputStream data, boolean toBase64) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE encryptiondata
- InputStream to encrypttoBase64
- true if resulting InputStream should contain base64,
IOException
- problems with the data InputStream
GeneralSecurityException
- problems encryptingpublic static byte[] encrypt(String cipher, char[] pwd, byte[] data, boolean toBase64, boolean useSalt) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE encryptiondata
- byte array to encrypttoBase64
- true if resulting InputStream should contain base64,
useSalt
- true if a salt should be used to derive the key.
useSalt
is true.
IOException
- problems with the data InputStream
GeneralSecurityException
- problems encryptingpublic static InputStream encrypt(String cipher, char[] pwd, InputStream data, boolean toBase64, boolean useSalt) throws IOException, GeneralSecurityException
cipher
- The OpenSSL compatible cipher to use (try "man enc" on a
unix box to see what's possible). Some examples:
pwd
- password to use for this PBE encryptiondata
- InputStream to encrypttoBase64
- true if resulting InputStream should contain base64,
useSalt
- true if a salt should be used to derive the key.
useSalt
is true.
IOException
- problems with the data InputStream
GeneralSecurityException
- problems encryptingpublic static byte[] decrypt(String cipher, byte[] key, byte[] iv, byte[] encrypted) throws IOException, GeneralSecurityException
IOException
GeneralSecurityException
public static InputStream decrypt(String cipher, byte[] key, byte[] iv, InputStream encrypted) throws IOException, GeneralSecurityException
IOException
GeneralSecurityException
public static byte[] encrypt(String cipher, byte[] key, byte[] iv, byte[] data) throws IOException, GeneralSecurityException
IOException
GeneralSecurityException
public static byte[] encrypt(String cipher, byte[] key, byte[] iv, byte[] data, boolean toBase64) throws IOException, GeneralSecurityException
IOException
GeneralSecurityException
public static InputStream encrypt(String cipher, byte[] key, byte[] iv, InputStream data) throws IOException, GeneralSecurityException
IOException
GeneralSecurityException
public static InputStream encrypt(String cipher, byte[] key, byte[] iv, InputStream data, boolean toBase64) throws IOException, GeneralSecurityException
IOException
GeneralSecurityException
public static DerivedKey deriveKey(char[] password, byte[] salt, int keySize, boolean des2) throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static DerivedKey deriveKey(char[] password, byte[] salt, int keySize, int ivSize, boolean des2) throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static OpenSSL.CipherInfo lookup(String openSSLCipher)
openSSLCipher
- OpenSSL cipher name, e.g. "des3" or "des-ede3-cbc".
Try "man enc" on a unix box to see what's possible.
public static void main(String[] args) throws IOException, GeneralSecurityException
args
- command line arguments: [password] [cipher] [file-to-decrypt]
IOException
- problems with the [file-to-decrypt]
GeneralSecurityException
- decryption problems
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |