Interface SecretBox.Native
- All Known Implementing Classes:
LazySodium,LazySodiumJava
- Enclosing interface:
- SecretBox
public static interface SecretBox.Native
-
Method Summary
Modifier and TypeMethodDescriptionbooleancryptoSecretBoxDetached(byte[] cipherText, byte[] mac, byte[] message, long messageLen, byte[] nonce, byte[] key) Encrypts a message.booleancryptoSecretBoxEasy(byte[] cipherText, byte[] message, long messageLen, byte[] nonce, byte[] key) Encrypts a message using a key generated bycryptoSecretBoxKeygen(byte[]).voidcryptoSecretBoxKeygen(byte[] key) Creates a random key.booleancryptoSecretBoxOpenDetached(byte[] message, byte[] cipherText, byte[] mac, long cipherTextLen, byte[] nonce, byte[] key) Decrypts a message with the mac and the cipher provided separately.booleancryptoSecretBoxOpenEasy(byte[] message, byte[] cipherText, long cipherTextLen, byte[] nonce, byte[] key) Decrypts and verifies a message using a key generated bycryptoSecretBoxKeygen(byte[]).
-
Method Details
-
cryptoSecretBoxKeygen
void cryptoSecretBoxKeygen(byte[] key) Creates a random key. It is equivalent to callingRandom.randomBytesBuf(int)but improves code clarity and can prevent misuse by ensuring that the provided key length is always correct.- Parameters:
key- The key which is of sizeSecretBox.KEYBYTES.
-
cryptoSecretBoxEasy
boolean cryptoSecretBoxEasy(byte[] cipherText, byte[] message, long messageLen, byte[] nonce, byte[] key) Encrypts a message using a key generated bycryptoSecretBoxKeygen(byte[]).- Parameters:
cipherText- The cipher text. Should be at leastSecretBox.MACBYTES+messageLen.message- The message to encrypt.messageLen- The message byte array length.nonce- A nonce of sizeSecretBox.NONCEBYTESgenerated byRandom.randomBytesBuf(int).key- The symmetric key generated bycryptoSecretBoxKeygen(byte[]).- Returns:
- True if successful.
-
cryptoSecretBoxOpenEasy
boolean cryptoSecretBoxOpenEasy(byte[] message, byte[] cipherText, long cipherTextLen, byte[] nonce, byte[] key) Decrypts and verifies a message using a key generated bycryptoSecretBoxKeygen(byte[]).- Parameters:
message- The message will be put into here once decrypted.cipherText- The cipher produced bycryptoSecretBoxEasy(byte[], byte[], long, byte[], byte[]).cipherTextLen- The cipher text length.nonce- This has to be the same nonce that was used when encrypting usingcryptoSecretBoxEasy.key- The key generated bycryptoSecretBoxKeygen(byte[]).- Returns:
- True if successful.
-
cryptoSecretBoxDetached
boolean cryptoSecretBoxDetached(byte[] cipherText, byte[] mac, byte[] message, long messageLen, byte[] nonce, byte[] key) Encrypts a message. Alongside the cipher a mac is returned which can be stored in separate locations.- Parameters:
cipherText- The encrypted message of lengthmessageLen.mac- The mac.message- The message to encrypt.messageLen- The message's length.nonce- A randomly generated nonce of sizeSecretBox.NONCEBYTES. UseRandom.randomBytesBuf(int).key- The key generated bycryptoSecretBoxKeygen(byte[]).- Returns:
- True if successful.
-
cryptoSecretBoxOpenDetached
boolean cryptoSecretBoxOpenDetached(byte[] message, byte[] cipherText, byte[] mac, long cipherTextLen, byte[] nonce, byte[] key) Decrypts a message with the mac and the cipher provided separately.- Parameters:
message- The message length which is the same size ascipherTextLen.cipherText- The cipher.mac- The mac.cipherTextLen- The cipher text length.nonce- The nonce that was used incryptoSecretBoxDetached(byte[], byte[], byte[], long, byte[], byte[]).key- The key generated bycryptoSecretBoxKeygen(byte[]).- Returns:
- True if successful.
-