Package com.neilalexander.jnacl
Class NaCl
java.lang.Object
com.neilalexander.jnacl.NaCl
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringasHex(byte[] buf) static StringasHex(int[] buf) byte[]decrypt(byte[] input, byte[] nonce) byte[]decrypt(byte[] input, int inputlength, byte[] nonce) static byte[]derivePublicKey(byte[] privatekey) byte[]encrypt(byte[] input, byte[] nonce) byte[]encrypt(byte[] input, int inputlength, byte[] nonce) static voidgenkeypair(byte[] publickey, byte[] privatekey) static voidgenkeypair(byte[] publickey, byte[] privatekey, byte[] seed) static byte[]static voidselfTest()static byte[]streamCryptData(byte[] input, byte[] key, byte[] nonce) static byte[]symmetricDecryptData(byte[] input, byte[] key, byte[] nonce) static booleansymmetricDecryptDataInplace(byte[] io, byte[] key, byte[] nonce) In-place version ofsymmetricDecryptData(byte[], byte[], byte[])that stores the output in the same byte array as the input.static byte[]symmetricEncryptData(byte[] input, byte[] key, byte[] nonce) static voidsymmetricEncryptDataInplace(byte[] io, byte[] key, byte[] nonce) In-place version ofsymmetricEncryptData(byte[], byte[], byte[])that stores the output in the same byte array as the input.
-
Field Details
-
PUBLICKEYBYTES
public static final int PUBLICKEYBYTES- See Also:
-
SECRETKEYBYTES
public static final int SECRETKEYBYTES- See Also:
-
BEFORENMBYTES
public static final int BEFORENMBYTES- See Also:
-
NONCEBYTES
public static final int NONCEBYTES- See Also:
-
ZEROBYTES
public static final int ZEROBYTES- See Also:
-
BOXZEROBYTES
public static final int BOXZEROBYTES- See Also:
-
BOXOVERHEAD
public static final int BOXOVERHEAD- See Also:
-
SYMMKEYBYTES
public static final int SYMMKEYBYTES- See Also:
-
STREAMKEYBYTES
public static final int STREAMKEYBYTES- See Also:
-
-
Constructor Details
-
NaCl
public NaCl(byte[] privatekey, byte[] publickey) -
NaCl
-
-
Method Details
-
encrypt
public byte[] encrypt(byte[] input, byte[] nonce) -
encrypt
public byte[] encrypt(byte[] input, int inputlength, byte[] nonce) -
decrypt
public byte[] decrypt(byte[] input, byte[] nonce) -
decrypt
public byte[] decrypt(byte[] input, int inputlength, byte[] nonce) -
genkeypair
public static void genkeypair(byte[] publickey, byte[] privatekey) -
genkeypair
public static void genkeypair(byte[] publickey, byte[] privatekey, byte[] seed) -
derivePublicKey
public static byte[] derivePublicKey(byte[] privatekey) -
symmetricEncryptData
public static byte[] symmetricEncryptData(byte[] input, byte[] key, byte[] nonce) -
symmetricEncryptDataInplace
public static void symmetricEncryptDataInplace(byte[] io, byte[] key, byte[] nonce) In-place version ofsymmetricEncryptData(byte[], byte[], byte[])that stores the output in the same byte array as the input. The input data must begin at offsetBOXOVERHEADin the array (the first BOXOVERHEAD bytes are ignored and will be overwritten with the message authentication code during encryption).- Parameters:
io- plaintext on input (starting at offset BOXOVERHEAD), ciphertext on return (full array)key- encryption keynonce- encryption nonce
-
symmetricDecryptData
public static byte[] symmetricDecryptData(byte[] input, byte[] key, byte[] nonce) -
symmetricDecryptDataInplace
public static boolean symmetricDecryptDataInplace(byte[] io, byte[] key, byte[] nonce) In-place version ofsymmetricDecryptData(byte[], byte[], byte[])that stores the output in the same byte array as the input. Note that the decrypted output is shorter than the input, so the lastBOXOVERHEADbytes should be ignored in the decrypted output.- Parameters:
io- ciphertext on input (full array), plaintext on output (last BOXOVERHEAD bytes set to zero)key- encryption keynonce- encryption nonce- Returns:
- decryption successful true/false
-
streamCryptData
public static byte[] streamCryptData(byte[] input, byte[] key, byte[] nonce) -
getBinary
-
asHex
-
asHex
-
selfTest
public static void selfTest()
-