Interface SecretBox.Native

    • Method Detail

      • 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.
      • 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.