Beispiel #1
0
        /// <summary> Both decrypt and verify the given <paramref name="encrypted"/> payload.
        /// Decrypt it with the given <paramref name="privateKey"/>,
        /// and verify that it was signed with the private key that matches <paramref name="publicKey"/> </summary>
        /// <param name="encrypted"> Encrypted payload to decrypt and verify </param>
        /// <param name="publicKey"> Public key to verify signature with </param>
        /// <param name="privateKey"> Private key to decrypt with </param>
        /// <param name="result"> place to store output </param>
        /// <param name="password"> optional password to use </param>
        /// <returns> True, if decryption and verification were successful. False otherwise. </returns>
        public static bool DecryptAndVerify(string encrypted, string publicKey, string privateKey, out string result, string password = "******")
        {
            MemoryStream ins         = new MemoryStream(encrypted.ToBytesUTF8());
            MemoryStream outs        = new MemoryStream();
            MemoryStream publicKeys  = new MemoryStream(publicKey.ToBytesUTF8());
            MemoryStream privateKeys = new MemoryStream(privateKey.ToBytesUTF8());

            try {
                instance.DecryptStreamAndVerify(ins, outs, publicKeys, privateKeys, password);
                result = Encoding.UTF8.GetString(outs.ToArray()).Replace("\r\n", "\n");
                return(true);
            } catch (Exception) {
                result = null;
                return(false);
            }
        }