本文整理汇总了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"))
//.........这里部分代码省略.........
示例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);
}
示例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);
}