/// <summary>
        /// Verifies the specified signature using original data and signer's Public key.
        /// </summary>
        public override bool Verify(byte[] data, byte[] signature, IPublicKey signerKey)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }

            try
            {
                using (var virgilSigner = new VirgilSigner())
                {
                    var isValid = virgilSigner.Verify(data, signature, signerKey.Get().Value);
                    return(isValid);
                }
            }
            catch (Exception ex)
            {
                throw new CryptoException(ex.Message);
            }
        }
 /// <summary>
 /// Exports the Public key into material representation.
 /// </summary>
 public override byte[] ExportPublicKey(IPublicKey publicKey)
 {
     try
     {
         return(VirgilKeyPair.PublicKeyToDER(publicKey.Get().Value));
     }
     catch (Exception ex)
     {
         throw new CryptoException(ex.Message);
     }
 }
        /// <summary>
        /// Verifies the specified signature using original stream and signer's Public key.
        /// </summary>
        public override bool Verify(Stream inputStream, byte[] signature, IPublicKey publicKey)
        {
            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }

            try
            {
                using (var streamSigner = new VirgilStreamSigner())
                {
                    var source  = new VirgilStreamDataSource(inputStream);
                    var isValid = streamSigner.Verify(source, signature, publicKey.Get().Value);
                    return(isValid);
                }
            }
            catch (Exception ex)
            {
                throw new CryptoException(ex.Message);
            }
        }
        /// <summary>
        /// Decrypts and verifies the data.
        /// </summary>
        /// <param name="cipherData">The cipher data.</param>
        /// <param name="privateKey">The Private key to decrypt.</param>
        /// <param name="publicKey">The Public key to verify.</param>
        /// <returns>The decrypted data</returns>
        /// <exception cref="Virgil.SDK.Exceptions.SignatureIsNotValidException"></exception>
        /// <exception cref="Virgil.SDK.Exceptions.CryptoException"></exception>
        public override byte[] DecryptThenVerify(byte[] cipherData, IPrivateKey privateKey, IPublicKey publicKey)
        {
            try
            {
                using (var signer = new VirgilSigner())
                    using (var cipher = new VirgilCipher())
                    {
                        var decryptedData = cipher.DecryptWithKey(cipherData, privateKey.Get().ReceiverId, privateKey.Get().Value);
                        var signature     = cipher.CustomParams().GetData(this.CustomParamKeySignature);

                        var isValid = signer.Verify(decryptedData, signature, publicKey.Get().Value);
                        if (!isValid)
                        {
                            throw new SignatureIsNotValidException();
                        }

                        return(decryptedData);
                    }
            }
            catch (Exception ex)
            {
                throw new CryptoException(ex.Message);
            }
        }