|
|||||||||
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(java.lang.String cipher,
byte[] key,
byte[] iv,
byte[] encrypted)
|
static java.io.InputStream |
decrypt(java.lang.String cipher,
byte[] key,
byte[] iv,
java.io.InputStream encrypted)
|
static byte[] |
decrypt(java.lang.String cipher,
char[] pwd,
byte[] encrypted)
Decrypts data using a password and an OpenSSL compatible cipher name. |
static java.io.InputStream |
decrypt(java.lang.String cipher,
char[] pwd,
java.io.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(java.lang.String cipher,
byte[] key,
byte[] iv,
byte[] data)
|
static byte[] |
encrypt(java.lang.String cipher,
byte[] key,
byte[] iv,
byte[] data,
boolean toBase64)
|
static java.io.InputStream |
encrypt(java.lang.String cipher,
byte[] key,
byte[] iv,
java.io.InputStream data)
|
static java.io.InputStream |
encrypt(java.lang.String cipher,
byte[] key,
byte[] iv,
java.io.InputStream data,
boolean toBase64)
|
static byte[] |
encrypt(java.lang.String cipher,
char[] pwd,
byte[] data)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static byte[] |
encrypt(java.lang.String cipher,
char[] pwd,
byte[] data,
boolean toBase64)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static byte[] |
encrypt(java.lang.String cipher,
char[] pwd,
byte[] data,
boolean toBase64,
boolean useSalt)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static java.io.InputStream |
encrypt(java.lang.String cipher,
char[] pwd,
java.io.InputStream data)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static java.io.InputStream |
encrypt(java.lang.String cipher,
char[] pwd,
java.io.InputStream data,
boolean toBase64)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static java.io.InputStream |
encrypt(java.lang.String cipher,
char[] pwd,
java.io.InputStream data,
boolean toBase64,
boolean useSalt)
Encrypts data using a password and an OpenSSL compatible cipher name. |
static OpenSSL.CipherInfo |
lookup(java.lang.String openSSLCipher)
Converts the way OpenSSL names its ciphers into a Java-friendly naming. |
static void |
main(java.lang.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(java.lang.String cipher, char[] pwd, byte[] encrypted) throws java.io.IOException, java.security.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.
java.io.IOException
- problems with encrypted bytes (unlikely!)
java.security.GeneralSecurityException
- problems decryptingpublic static java.io.InputStream decrypt(java.lang.String cipher, char[] pwd, java.io.InputStream encrypted) throws java.io.IOException, java.security.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.
java.io.IOException
- problems with InputStream
java.security.GeneralSecurityException
- problems decryptingpublic static byte[] encrypt(java.lang.String cipher, char[] pwd, byte[] data) throws java.io.IOException, java.security.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
java.io.IOException
- problems with the data byte array
java.security.GeneralSecurityException
- problems encryptingpublic static java.io.InputStream encrypt(java.lang.String cipher, char[] pwd, java.io.InputStream data) throws java.io.IOException, java.security.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
java.io.IOException
- problems with the data InputStream
java.security.GeneralSecurityException
- problems encryptingpublic static byte[] encrypt(java.lang.String cipher, char[] pwd, byte[] data, boolean toBase64) throws java.io.IOException, java.security.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,
java.io.IOException
- problems with the data byte array
java.security.GeneralSecurityException
- problems encryptingpublic static java.io.InputStream encrypt(java.lang.String cipher, char[] pwd, java.io.InputStream data, boolean toBase64) throws java.io.IOException, java.security.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,
java.io.IOException
- problems with the data InputStream
java.security.GeneralSecurityException
- problems encryptingpublic static byte[] encrypt(java.lang.String cipher, char[] pwd, byte[] data, boolean toBase64, boolean useSalt) throws java.io.IOException, java.security.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.
java.io.IOException
- problems with the data InputStream
java.security.GeneralSecurityException
- problems encryptingpublic static java.io.InputStream encrypt(java.lang.String cipher, char[] pwd, java.io.InputStream data, boolean toBase64, boolean useSalt) throws java.io.IOException, java.security.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.
java.io.IOException
- problems with the data InputStream
java.security.GeneralSecurityException
- problems encryptingpublic static byte[] decrypt(java.lang.String cipher, byte[] key, byte[] iv, byte[] encrypted) throws java.io.IOException, java.security.GeneralSecurityException
java.io.IOException
java.security.GeneralSecurityException
public static java.io.InputStream decrypt(java.lang.String cipher, byte[] key, byte[] iv, java.io.InputStream encrypted) throws java.io.IOException, java.security.GeneralSecurityException
java.io.IOException
java.security.GeneralSecurityException
public static byte[] encrypt(java.lang.String cipher, byte[] key, byte[] iv, byte[] data) throws java.io.IOException, java.security.GeneralSecurityException
java.io.IOException
java.security.GeneralSecurityException
public static byte[] encrypt(java.lang.String cipher, byte[] key, byte[] iv, byte[] data, boolean toBase64) throws java.io.IOException, java.security.GeneralSecurityException
java.io.IOException
java.security.GeneralSecurityException
public static java.io.InputStream encrypt(java.lang.String cipher, byte[] key, byte[] iv, java.io.InputStream data) throws java.io.IOException, java.security.GeneralSecurityException
java.io.IOException
java.security.GeneralSecurityException
public static java.io.InputStream encrypt(java.lang.String cipher, byte[] key, byte[] iv, java.io.InputStream data, boolean toBase64) throws java.io.IOException, java.security.GeneralSecurityException
java.io.IOException
java.security.GeneralSecurityException
public static DerivedKey deriveKey(char[] password, byte[] salt, int keySize, boolean des2) throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException
public static DerivedKey deriveKey(char[] password, byte[] salt, int keySize, int ivSize, boolean des2) throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException
public static OpenSSL.CipherInfo lookup(java.lang.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(java.lang.String[] args) throws java.io.IOException, java.security.GeneralSecurityException
args
- command line arguments: [password] [cipher] [file-to-decrypt]
java.io.IOException
- problems with the [file-to-decrypt]
java.security.GeneralSecurityException
- decryption problems
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |