当前位置: 首页>>代码示例>>C#>>正文


C# RSACryptoServiceProvider.VerifyHash方法代码示例

本文整理汇总了C#中RSACryptoServiceProvider.VerifyHash方法的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.VerifyHash方法的具体用法?C# RSACryptoServiceProvider.VerifyHash怎么用?C# RSACryptoServiceProvider.VerifyHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RSACryptoServiceProvider的用法示例。


在下文中一共展示了RSACryptoServiceProvider.VerifyHash方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

    private void Process()
    {
        m_LVL_Received = true;
        m_ButtonMessage = "Check LVL";
        m_ButtonEnabled = true;

        if (m_LVLCheck == null)
            return;

        int responseCode	= m_LVLCheck.Get<int>("_arg0");
        string message		= m_LVLCheck.Get<string>("_arg1");
        string signature	= m_LVLCheck.Get<string>("_arg2");

        m_LVLCheck = null;

        m_ResponseCode_Received = responseCode.ToString();
        if (responseCode < 0 || string.IsNullOrEmpty(message) || string.IsNullOrEmpty(signature))
        {
            m_PackageName_Received = "<Failed>";
            return;
        }

        byte[] message_bytes = System.Text.Encoding.UTF8.GetBytes(message);
        byte[] signature_bytes = System.Convert.FromBase64String(signature);
        RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
        csp.ImportParameters(m_PublicKey);
        SHA1Managed sha1 = new SHA1Managed();
        bool match = csp.VerifyHash(sha1.ComputeHash(message_bytes), CryptoConfig.MapNameToOID("SHA1"), signature_bytes);

        if (!match)
        {
            m_ResponseCode_Received = "<Failed>";
            m_PackageName_Received = "<Invalid Signature>";
            return;
        }

        int index = message.IndexOf(':');
        string mainData, extraData;
        if (-1 == index)
        {
            mainData = message;
            extraData = "";
        }
        else
        {
            mainData = message.Substring(0, index);
            extraData = index >= message.Length ? "" : message.Substring(index + 1);
        }

        string[] vars = mainData.Split('|');		// response | nonce | package | version | userid | timestamp

        if (vars[0].CompareTo(responseCode.ToString()) != 0)
        {
            m_ResponseCode_Received = "<Failed>";
            m_PackageName_Received = "<Response Mismatch>";
            return;
        }

        m_ResponseCode_Received		= vars[0];
        m_Nonce_Received			= System.Convert.ToInt32(vars[1]);
        m_PackageName_Received		= vars[2];
        m_VersionCode_Received		= System.Convert.ToInt32(vars[3]);
        m_UserID_Received			= vars[4];
        System.Int64 ticks			= ConvertEpochSecondsToTicks(System.Convert.ToInt64(vars[5]));
        m_Timestamp_Received		= new System.DateTime(ticks).ToLocalTime().ToString();

        if (!string.IsNullOrEmpty(extraData))
        {
            Dictionary<string, string> extrasDecoded = DecodeExtras(extraData);

            if (extrasDecoded.ContainsKey("GR"))
            {
                m_MaxRetry_Received = System.Convert.ToInt32(extrasDecoded["GR"]);
            }
            else
            {
                m_MaxRetry_Received = 0;
            }

            if (extrasDecoded.ContainsKey("VT"))
            {
                ticks = ConvertEpochSecondsToTicks(System.Convert.ToInt64(extrasDecoded["VT"]));
                m_LicenceValidityTimestamp_Received = new System.DateTime(ticks).ToLocalTime().ToString();
            }
            else
            {
                m_LicenceValidityTimestamp_Received = null;
            }

            if (extrasDecoded.ContainsKey("GT"))
            {
                ticks = ConvertEpochSecondsToTicks(System.Convert.ToInt64(extrasDecoded["GT"]));
                m_GracePeriodTimestamp_Received = new System.DateTime(ticks).ToLocalTime().ToString();
            }
            else
            {
                m_GracePeriodTimestamp_Received = null;
            }

            if (extrasDecoded.ContainsKey("UT"))
//.........这里部分代码省略.........
开发者ID:Unity-Technologies,项目名称:GooglePlayLicenseVerification,代码行数:101,代码来源:CheckLVLButton.cs

示例2: VerifyHashSignature

        private static void VerifyHashSignature(
            byte[] signature,
            byte[] dataHash,
            string hashAlgorithmName,
            RSAParameters rsaParameters)
        {
            RSAParameters publicOnly = new RSAParameters
            {
                Modulus = rsaParameters.Modulus,
                Exponent = rsaParameters.Exponent,
            };

            bool signatureMatched;

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(publicOnly);
                signatureMatched = rsa.VerifyHash(dataHash, hashAlgorithmName, signature);
            }

            Assert.True(signatureMatched);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:22,代码来源:SignVerify.cs

示例3: VerifyLegacySignVerifyHash

        // (false, false) is not required, that would be equivalent to the RSA AlgorithmImplementation suite.
        public static void VerifyLegacySignVerifyHash(bool useLegacySign, bool useLegacyVerify)
        {
            byte[] dataHash, signature;

            using (HashAlgorithm hash = SHA256.Create())
            {
                dataHash = hash.ComputeHash(TestData.HelloBytes);
            }

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(TestData.RSA2048Params);

                signature = useLegacySign ?
                    rsa.SignHash(dataHash, "SHA256") :
                    rsa.SignHash(dataHash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
            }

            bool verified;

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(
                    new RSAParameters
                    {
                        Modulus = TestData.RSA2048Params.Modulus,
                        Exponent = TestData.RSA2048Params.Exponent,
                    });

                verified = useLegacyVerify ?
                    rsa.VerifyHash(dataHash, "SHA256", signature) :
                    rsa.VerifyHash(dataHash, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
            }

            Assert.True(verified);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:37,代码来源:RSACryptoServiceProviderBackCompat.cs


注:本文中的RSACryptoServiceProvider.VerifyHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。