Example #1
0
        public static bool VerifySignedHash(string strDataToVerify, string strSignedData, string strPublicKeyFilePath)
        {
            var signedData = Convert.FromBase64String(strSignedData);

            var byteConverter = new UTF8Encoding();
            var dataToVerify = byteConverter.GetBytes(strDataToVerify);
            try
            {
                var sPublicKeyPem = File.ReadAllText(strPublicKeyFilePath);
                var rsa = new RSACryptoServiceProvider { PersistKeyInCsp = false };

                rsa.LoadPublicKeyPem(sPublicKeyPem);

                return rsa.VerifyData(dataToVerify, "SHA256", signedData);
            }
            catch (CryptographicException e)
            {
                Console.WriteLine(e.Message);

                return false;
            }
        }