|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.cryptonode.jncryptor.AES256JNCryptor
public class AES256JNCryptor
This JNCryptor
instance produces data in version 3 format. It can
read data in any format since version 2.
| version | options | encryption salt | HMAC salt | IV | ... ciphertext ... | HMAC | | 0 | 1 | 2->9 | 10->17 | 18->33 | <- ... -> | (n-32) -> n |
0x00
if keys are used, 0x01
if a
password is used.
The encryption key is derived using the PKBDF2 function, using a random
eight-byte encryption salt, the supplied password and 10,000 iterations. The
iteration count can be changed using the setPBKDFIterations(int)
method. The HMAC key is derived in a similar fashion, using its own random
eight-byte HMAC salt. Both salt values are stored in the ciphertext output
(as shown above).
The ciphertext is AES-256-CBC encrypted, using a randomly generated IV and the encryption key (described above), with PKCS #5 padding.
The HMAC is calculated across all the data (except the HMAC itself, of course), generated using the HMAC key described above and the SHA-256 PRF.
This class is thread-safe. Multiple threads may share one instance of this class, or each thread may have its own instance.
See https://github .com/rnapier/RNCryptor/wiki/Data-Format, from which most of the information above was shamelessly copied.
Constructor Summary | |
---|---|
AES256JNCryptor()
Creates a new AES256JNCryptor instance. |
|
AES256JNCryptor(int iterations)
Creates a new AES256JNCryptor instance that uses a specific number
of PBKDF iterations. |
Method Summary | |
---|---|
byte[] |
decryptData(byte[] ciphertext,
char[] password)
Decrypts data with the supplied password. |
byte[] |
decryptData(byte[] ciphertext,
SecretKey decryptionKey,
SecretKey hmacKey)
Decrypts data with the supplied keys. |
byte[] |
encryptData(byte[] plaintext,
char[] password)
Encrypts data with the supplied password. |
byte[] |
encryptData(byte[] plaintext,
char[] password,
byte[] encryptionSalt,
byte[] hmacSalt,
byte[] iv)
Encrypts data with the supplied password, salt values and IV. |
byte[] |
encryptData(byte[] plaintext,
PasswordKey encryptionKey,
PasswordKey hmacKey)
Encrypts data using pre-computed keys, producing data in the password output format (i.e. |
byte[] |
encryptData(byte[] plaintext,
SecretKey encryptionKey,
SecretKey hmacKey)
Encrypts data with the supplied keys. |
PasswordKey |
getPasswordKey(char[] password)
Generates a key from a password and a random salt. |
int |
getPBKDFIterations()
Gets the number of iterations used by this JNCryptor . |
int |
getVersionNumber()
Returns the version number of the data format produced by this JNCryptor . |
SecretKey |
keyForPassword(char[] password,
byte[] salt)
Generates a key given a password and salt using a PBKDF. |
void |
setPBKDFIterations(int iterations)
Changes the number of iterations used by this JNCryptor . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AES256JNCryptor()
AES256JNCryptor
instance. Uses the default number of
PBKDF iterations.
public AES256JNCryptor(int iterations)
AES256JNCryptor
instance that uses a specific number
of PBKDF iterations.
iterations
- the number of PBKDF iterations to performMethod Detail |
---|
public SecretKey keyForPassword(char[] password, byte[] salt) throws CryptorException
JNCryptor
keyForPassword
in interface JNCryptor
password
- password to use for PBKDF. Cannot be empty or null
.salt
- salt for password, cannot be null
CryptorException
public int getPBKDFIterations()
JNCryptor
JNCryptor
.
getPBKDFIterations
in interface JNCryptor
public void setPBKDFIterations(int iterations)
JNCryptor
JNCryptor
.
setPBKDFIterations
in interface JNCryptor
public byte[] decryptData(byte[] ciphertext, char[] password) throws CryptorException
JNCryptor
decryptData
in interface JNCryptor
ciphertext
- data to decrypt. Must be in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor
-Spec-v3.mdpassword
- password to use for the decryption. Cannot be empty or
null
.
InvalidHMACException
CryptorException
public byte[] encryptData(byte[] plaintext, char[] password, byte[] encryptionSalt, byte[] hmacSalt, byte[] iv) throws CryptorException
JNCryptor
encryptData
in interface JNCryptor
plaintext
- the plaintextpassword
- the password (cannot be null
or empty)encryptionSalt
- eight bytes of random salt valuehmacSalt
- eight bytes of random salt valueiv
- sixteen byte AES IV
CryptorException
- if an error occurredpublic byte[] encryptData(byte[] plaintext, char[] password) throws CryptorException
JNCryptor
encryptData
in interface JNCryptor
plaintext
- the data to encryptpassword
- password to use for the encryption. Cannot be empty or
null
.
CryptorException
public int getVersionNumber()
JNCryptor
JNCryptor
.
getVersionNumber
in interface JNCryptor
public byte[] decryptData(byte[] ciphertext, SecretKey decryptionKey, SecretKey hmacKey) throws CryptorException, InvalidHMACException
JNCryptor
decryptData
in interface JNCryptor
ciphertext
- data to decrypt. Must be in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor
-Spec-v3.mddecryptionKey
- the key to decrypt withhmacKey
- the key to verify the HMAC with
InvalidHMACException
CryptorException
public byte[] encryptData(byte[] plaintext, SecretKey encryptionKey, SecretKey hmacKey) throws CryptorException
JNCryptor
encryptData
in interface JNCryptor
plaintext
- the data to encryptencryptionKey
- key to use for encryptionhmacKey
- key to use for computing the HMAC
CryptorException
public PasswordKey getPasswordKey(char[] password) throws CryptorException
JNCryptor
getPasswordKey
in interface JNCryptor
password
- password to use for PBKDF. Cannot be empty or null
.
CryptorException
public byte[] encryptData(byte[] plaintext, PasswordKey encryptionKey, PasswordKey hmacKey) throws CryptorException
JNCryptor
encryptData
in interface JNCryptor
plaintext
- the plaintext to encryptencryptionKey
- the pre-computed encryption keyhmacKey
- the pre-computer HMAC key
CryptorException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |