/// <summary>Opens a SealedPublicKeyBox</summary> /// <param name="cipherText">The cipherText to be opened.</param> /// <param name="recipientSecretKey">The recipient's secret key.</param> /// <param name="recipientPublicKey">The recipient's public key.</param> /// <returns>The decrypted message.</returns> /// <exception cref="KeyOutOfRangeException"></exception> /// <exception cref="CryptographicException"></exception> public static byte[] Open(byte[] cipherText, byte[] recipientSecretKey, byte[] recipientPublicKey) { //validate the length of the recipient secret key if (recipientSecretKey == null || recipientSecretKey.Length != RecipientSecretKeyBytes) { throw new KeyOutOfRangeException("recipientPublicKey", (recipientSecretKey == null) ? 0 : recipientSecretKey.Length, string.Format("recipientSecretKey must be {0} bytes in length.", RecipientSecretKeyBytes)); } //validate the length of the recipient public key if (recipientPublicKey == null || recipientPublicKey.Length != RecipientPublicKeyBytes) { throw new KeyOutOfRangeException("recipientPublicKey", (recipientPublicKey == null) ? 0 : recipientPublicKey.Length, string.Format("recipientPublicKey must be {0} bytes in length.", RecipientPublicKeyBytes)); } var buffer = new byte[cipherText.Length - CryptoBoxSealbytes]; var ret = SodiumLibrary.crypto_box_seal_open(buffer, cipherText, cipherText.Length, recipientPublicKey, recipientSecretKey); if (ret != 0) { throw new CryptographicException("Failed to open SealedBox"); } return(buffer); }