encrypt
fun encrypt(plaintext: String, conversationKey: ByteArray, nonce: ByteArray = generateNonce()): Nip44CipherText
Encrypts a plaintext message using NIP-44.
Encrypts the message with the following steps:
Pads the plaintext using NIP-44 padding scheme
Derives message keys from conversation key and nonce
Encrypts padded plaintext with ChaCha20
Computes HMAC-SHA256 over nonce and ciphertext
Securely clears derived keys from memory
Return
Nip44CipherText containing version, nonce, ciphertext, and MAC
Parameters
plaintext
The message to encrypt (1-65535 bytes UTF-8)
conversation Key
The 32-byte conversation key
nonce
The 32-byte random nonce (auto-generated if not provided)
Throws
if plaintext length is invalid or keys are wrong size