Interface SecretBox.Native

All Known Implementing Classes:
LazySodium, LazySodiumJava
Enclosing interface:
SecretBox

public static interface SecretBox.Native
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    cryptoSecretBoxDetached(byte[] cipherText, byte[] mac, byte[] message, long messageLen, byte[] nonce, byte[] key)
    Encrypts a message.
    boolean
    cryptoSecretBoxEasy(byte[] cipherText, byte[] message, long messageLen, byte[] nonce, byte[] key)
    Encrypts a message using a key generated by cryptoSecretBoxKeygen(byte[]).
    void
    Creates a random key.
    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.
    boolean
    cryptoSecretBoxOpenEasy(byte[] message, byte[] cipherText, long cipherTextLen, byte[] nonce, byte[] key)
    Decrypts and verifies a message using a key generated by cryptoSecretBoxKeygen(byte[]).
  • Method Details

    • cryptoSecretBoxKeygen

      void cryptoSecretBoxKeygen(byte[] key)
      Creates a random key. It is equivalent to calling Random.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 size SecretBox.KEYBYTES.
    • cryptoSecretBoxEasy

      boolean cryptoSecretBoxEasy(byte[] cipherText, byte[] message, long messageLen, byte[] nonce, byte[] key)
      Encrypts a message using a key generated by cryptoSecretBoxKeygen(byte[]).
      Parameters:
      cipherText - The cipher text. Should be at least SecretBox.MACBYTES + messageLen.
      message - The message to encrypt.
      messageLen - The message byte array length.
      nonce - A nonce of size SecretBox.NONCEBYTES generated by Random.randomBytesBuf(int).
      key - The symmetric key generated by cryptoSecretBoxKeygen(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 by cryptoSecretBoxKeygen(byte[]).
      Parameters:
      message - The message will be put into here once decrypted.
      cipherText - The cipher produced by cryptoSecretBoxEasy(byte[], byte[], long, byte[], byte[]).
      cipherTextLen - The cipher text length.
      nonce - This has to be the same nonce that was used when encrypting using cryptoSecretBoxEasy.
      key - The key generated by cryptoSecretBoxKeygen(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 length messageLen.
      mac - The mac.
      message - The message to encrypt.
      messageLen - The message's length.
      nonce - A randomly generated nonce of size SecretBox.NONCEBYTES. Use Random.randomBytesBuf(int).
      key - The key generated by cryptoSecretBoxKeygen(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 as cipherTextLen.
      cipherText - The cipher.
      mac - The mac.
      cipherTextLen - The cipher text length.
      nonce - The nonce that was used in cryptoSecretBoxDetached(byte[], byte[], byte[], long, byte[], byte[]).
      key - The key generated by cryptoSecretBoxKeygen(byte[]).
      Returns:
      True if successful.