INNER CODE UNIT · Swift

seal

jedisct1/swift-sodium · Sources/Sodium/Box.swift:42

    func seal(message: Bytes, recipientPublicKey: PublicKey, senderSecretKey: SecretKey) -> Bytes? {
        guard let (authenticatedCipherText, nonce): (Bytes, Nonce) = seal(message: message, recipientPublicKey: recipientPublicKey, senderSecretKey: senderSecretKey) else {
            return nil
        }
        return nonce + authenticatedCipherText
    }

    /// Encrypts a message using public-key authenticated encryption with specific nonce
    ///
    /// - Warning: Never reuse a nonce with the same key pair! Doing so compromises security.
    /// Consider using the methods that generate random nonces automatically.
    ///
    /// - Parameters:
    ///   - message: The plaintext message to encrypt
    ///   - recipientPublicKey: The recipient's 32-byte public key
    ///   - senderSecretKey: The sender's 32-byte secret key
    ///   - nonce: The 24-byte nonce (must be unique for this key pair)
    /// - Returns: Authenticated ciphertext (message.count + 16 bytes), or nil on failure

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…