org.cryptonode.jncryptor
Interface JNCryptor

All Known Implementing Classes:
AES256JNCryptor

public interface JNCryptor

A JNCryptor encrypts and decrypts data in a proprietary format originally devised by Rob Napier.

See https://github.com/rnapier/ RNCryptor for details on the original implementation in objective-c


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.
 

Method Detail

keyForPassword

SecretKey keyForPassword(char[] password,
                         byte[] salt)
                         throws CryptorException
Generates a key given a password and salt using a PBKDF.

Parameters:
password - password to use for PBKDF. Cannot be empty or null.
salt - salt for password, cannot be null
Returns:
the key
Throws:
CryptorException

getPasswordKey

PasswordKey getPasswordKey(char[] password)
                           throws CryptorException
Generates a key from a password and a random salt.

Parameters:
password - password to use for PBKDF. Cannot be empty or null.
Returns:
an object containing the key and the salt
Throws:
CryptorException
Since:
1.2.0

encryptData

byte[] encryptData(byte[] plaintext,
                   PasswordKey encryptionKey,
                   PasswordKey hmacKey)
                   throws CryptorException
Encrypts data using pre-computed keys, producing data in the password output format (i.e. including salt values).

Parameters:
plaintext - the plaintext to encrypt
encryptionKey - the pre-computed encryption key
hmacKey - the pre-computer HMAC key
Returns:
the ciphertext, in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor- Spec-v3.md
Throws:
CryptorException
Since:
1.2.0

encryptData

byte[] encryptData(byte[] plaintext,
                   char[] password,
                   byte[] encryptionSalt,
                   byte[] hmacSalt,
                   byte[] iv)
                   throws CryptorException
Encrypts data with the supplied password, salt values and IV.

Parameters:
plaintext - the plaintext
password - the password (cannot be null or empty)
encryptionSalt - eight bytes of random salt value
hmacSalt - eight bytes of random salt value
iv - sixteen byte AES IV
Returns:
the ciphertext, in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor- Spec-v3.md
Throws:
CryptorException - if an error occurred
Since:
1.2.0

decryptData

byte[] decryptData(byte[] ciphertext,
                   char[] password)
                   throws CryptorException,
                          InvalidHMACException
Decrypts data with the supplied password.

Parameters:
ciphertext - data to decrypt. Must be in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor -Spec-v3.md
password - password to use for the decryption. Cannot be empty or null.
Returns:
the plain text
Throws:
InvalidHMACException
CryptorException

decryptData

byte[] decryptData(byte[] ciphertext,
                   SecretKey decryptionKey,
                   SecretKey hmacKey)
                   throws CryptorException,
                          InvalidHMACException
Decrypts data with the supplied keys.

Parameters:
ciphertext - data to decrypt. Must be in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor -Spec-v3.md
decryptionKey - the key to decrypt with
hmacKey - the key to verify the HMAC with
Returns:
the plain text
Throws:
InvalidHMACException
CryptorException

encryptData

byte[] encryptData(byte[] plaintext,
                   char[] password)
                   throws CryptorException
Encrypts data with the supplied password.

Parameters:
plaintext - the data to encrypt
password - password to use for the encryption. Cannot be empty or null.
Returns:
the ciphertext, in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor- Spec-v3.md
Throws:
CryptorException

encryptData

byte[] encryptData(byte[] plaintext,
                   SecretKey encryptionKey,
                   SecretKey hmacKey)
                   throws CryptorException
Encrypts data with the supplied keys.

Parameters:
plaintext - the data to encrypt
encryptionKey - key to use for encryption
hmacKey - key to use for computing the HMAC
Returns:
the ciphertext, in the format described at https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor- Spec-v3.md
Throws:
CryptorException

getVersionNumber

int getVersionNumber()
Returns the version number of the data format produced by this JNCryptor.

Returns:
the version number

setPBKDFIterations

void setPBKDFIterations(int iterations)
Changes the number of iterations used by this JNCryptor.

Parameters:
iterations -
Since:
0.4

getPBKDFIterations

int getPBKDFIterations()
Gets the number of iterations used by this JNCryptor.

Returns:
the number of PBKDF2 iterations
Since:
1.0.0


Copyright © 2014. All Rights Reserved.