public class Crypto extends Object
This class provides default encryption using AES with a constant 128 bit key. If you want something more secure feel free to override the defaults however you please.
This class works in one of two ways, (1) in memory using Strings, or (2) via I/O streams (preferred for large amounts of data).
Crypo objects, or more specifically the default ciphers they create, are not threadsafe and are not computationally cheap, so a threadlocal factory method is provided for convenience. This is the preferred means of usage, but feel free to create these objects however you please.
Note that you can encrypt BLOB fields by specifying encryption in the configurator (Crypto is the default encryption mechanism for that).
Constructor and Description |
---|
Crypto()
Default crypto object
|
Crypto(String theKey)
Default crypto object
|
Modifier and Type | Method and Description |
---|---|
Cipher |
createDefaultCipher()
Create the default cipher
|
InputStream |
decrypt(InputStream in)
the decrypted input stream
|
OutputStream |
decrypt(OutputStream out)
the decrypted output stream
|
String |
decrypt(String cipherText)
Decrypt the string
|
InputStream |
encrypt(InputStream in)
Get the encrypted input stream
|
OutputStream |
encrypt(OutputStream out)
the encrypted output stream
|
String |
encrypt(String clearText)
Encrypt the string
|
static byte[] |
generateKeyBytes(String cipherName,
Integer keybits)
Generate a key.
|
static Crypto |
getThreadLocalCrypto() |
protected void |
init(String secret)
initialize the key and cipher
|
public Crypto()
public Crypto(String theKey)
theKey
- used to encrypt/decryptpublic static Crypto getThreadLocalCrypto()
public static byte[] generateKeyBytes(String cipherName, Integer keybits)
cipherName
- the name of the cipher, if null will default to "AES"keybits
- the number of bits in the key, if null will default to 128public Cipher createDefaultCipher()
protected void init(String secret)
secret
- public String encrypt(String clearText)
clearText
- public String decrypt(String cipherText)
cipherText
- public InputStream encrypt(InputStream in)
in
- public InputStream decrypt(InputStream in)
in
- public OutputStream encrypt(OutputStream out)
out
- public OutputStream decrypt(OutputStream out)
out
- Copyright © 2016 Internet2. All rights reserved.