本文整理汇总了C#中System.Security.Cryptography.RSAPKCS1SignatureDeformatter.VerifySignature方法的典型用法代码示例。如果您正苦于以下问题:C# RSAPKCS1SignatureDeformatter.VerifySignature方法的具体用法?C# RSAPKCS1SignatureDeformatter.VerifySignature怎么用?C# RSAPKCS1SignatureDeformatter.VerifySignature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.RSAPKCS1SignatureDeformatter
的用法示例。
在下文中一共展示了RSAPKCS1SignatureDeformatter.VerifySignature方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
/// <summary>
/// ��ע����Ϣ���ݲ��÷ǶԳƼ��ܵķ�ʽ����
/// </summary>
/// <param name="originalString">δ���ܵ��ı����������</param>
/// <param name="encrytedString">���ܺ���ı�����ע�����к�</param>
/// <returns>�����֤�ɹ�����True������ΪFalse</returns>
public static bool Validate(string originalString, string encrytedString)
{
bool bPassed = false;
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
try
{
rsa.FromXmlString(UIConstants.PublicKey); //��Կ
RSAPKCS1SignatureDeformatter formatter = new RSAPKCS1SignatureDeformatter(rsa);
formatter.SetHashAlgorithm("SHA1");
byte[] key = Convert.FromBase64String(encrytedString); //��֤
SHA1Managed sha = new SHA1Managed();
byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(originalString));
if (formatter.VerifySignature(name, key))
{
bPassed = true;
}
}
catch
{
}
}
return bPassed;
}
示例2: CerRSAVerifySignature
/// <summary>
/// 引用证书非对称加/解密RSA-公钥验签【OriginalString:原文;SignatureString:签名字符;pubkey_path:证书路径;CertificatePW:证书密码;SignType:签名摘要类型(1:MD5,2:SHA1)】
/// </summary>
public static bool CerRSAVerifySignature(string OriginalString, string SignatureString, string pubkey_path, string CertificatePW, int SignType)
{
byte[] OriginalByte = System.Text.Encoding.UTF8.GetBytes(OriginalString);
byte[] SignatureByte = Convert.FromBase64String(SignatureString);
X509Certificate2 x509_Cer1 = new X509Certificate2(pubkey_path, CertificatePW);
RSACryptoServiceProvider rsapub = (RSACryptoServiceProvider)x509_Cer1.PublicKey.Key;
rsapub.ImportCspBlob(rsapub.ExportCspBlob(false));
RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsapub);
byte[] HashData;
switch (SignType)
{
case 1:
f.SetHashAlgorithm("MD5");//摘要算法MD5
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
HashData = md5.ComputeHash(OriginalByte);
break;
default:
f.SetHashAlgorithm("SHA1");//摘要算法SHA1
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
HashData = sha.ComputeHash(OriginalByte);
break;
}
if (f.VerifySignature(HashData, SignatureByte))
{
return true;
}
else
{
return false;
}
}
示例3: ValidatePathWithEncodedRSAPKCS1SignatureAndPublicRSAKey
public static bool ValidatePathWithEncodedRSAPKCS1SignatureAndPublicRSAKey(string path, string base64Signature, string publicKey) {
try {
byte[] signature = Convert.FromBase64String(base64Signature);
byte[] data = File.ReadAllBytes(path);
SHA256CryptoServiceProvider cryptoTransformSHA256 = new SHA256CryptoServiceProvider();
byte[] sha256Hash = cryptoTransformSHA256.ComputeHash(data);
string cleanKey = "";
string[] lines = publicKey.Split(new char[] {'\n', '\r'});
foreach (string line in lines) {
cleanKey += line.Trim();
}
byte[] publicKeyData = Convert.FromBase64String(cleanKey);
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
provider.ImportCspBlob(publicKeyData);
RSAPKCS1SignatureDeformatter formatter = new RSAPKCS1SignatureDeformatter(provider);
formatter.SetHashAlgorithm("SHA256");
return formatter.VerifySignature(sha256Hash, signature);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
return false;
}
}
示例4: VerifySignature
public DigitalSignatureVerificationResult VerifySignature(DigitalSignatureVerificationArguments arguments)
{
var res = new DigitalSignatureVerificationResult();
try
{
var rsaProviderSender = new RSACryptoServiceProvider();
rsaProviderSender.FromXmlString(arguments.PublicKeyForSignatureVerification.ToString());
var deformatter = new RSAPKCS1SignatureDeformatter(rsaProviderSender);
deformatter.SetHashAlgorithm(_hashingService.HashAlgorithmCode());
var hashResult = _hashingService.Hash(arguments.CipherText);
res.SignaturesMatch = deformatter.VerifySignature(hashResult.HashedBytes, arguments.Signature);
if (res.SignaturesMatch)
{
var rsaProviderReceiver = new RSACryptoServiceProvider();
rsaProviderReceiver.FromXmlString(arguments.FullKeyForDecryption.ToString());
var decryptedBytes = rsaProviderReceiver.Decrypt(Convert.FromBase64String(arguments.CipherText), false);
res.DecodedText = Encoding.UTF8.GetString(decryptedBytes);
}
res.Success = true;
}
catch (Exception ex)
{
res.ExceptionMessage = ex.Message;
}
return res;
}
示例5: CompareCode
public static bool CompareCode(string regcode)
{
if (regcode == null || regcode == "")
{
return false;
}
try
{
string toolcode = GetDiskVolumeSerialNumber() + GetCpuSerialNumber();
string pubkey = "<RSAKeyValue><Modulus>xe3teTUwLgmbiwFJwWEQnshhKxgcasglGsfNVFTk0hdqKc9i7wb+gG7HOdPZLh65QyBcFfzdlrawwVkiPEL5kNTX1q3JW5J49mTVZqWd3w49reaLd8StHRYJdyGAL4ZovBhSTThETi+zYvgQ5SvCGkM6/xXOz+lkMaEgeFcjQQs=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
string prikey = "<RSAKeyValue><Modulus>xe3teTUwLgmbiwFJwWEQnshhKxgcasglGsfNVFTk0hdqKc9i7wb+gG7HOdPZLh65QyBcFfzdlrawwVkiPEL5kNTX1q3JW5J49mTVZqWd3w49reaLd8StHRYJdyGAL4ZovBhSTThETi+zYvgQ5SvCGkM6/xXOz+lkMaEgeFcjQQs=</Modulus><Exponent>AQAB</Exponent><P>5flMAd7IrUTx92yomBdJBPDzp1Kclpaw4uXB1Ht+YXqwLW/9icI6mcv7d2O0kuVLSWj8DPZJol9V8AtvHkC3oQ==</P><Q>3FRA9UWcFrVPvGR5bewcL7YqkCMZlybV/t6nCH+gyMfbEvgk+p04F+j8WiHDykWj+BahjScjwyF5SGADbrfJKw==</Q><DP>b4WOU1XbERNfF3JM67xW/5ttPNX185zN2Ko8bbMZXWImr1IgrD5RNqXRo1rphVbGRKoxmIOSv7flr8uLrisKIQ==</DP><DQ>otSZlSq2qomgvgg7PaOLSS+F0TQ/i1emO0/tffhkqT4ah7BgE97xP6puJWZivjAteAGxrxHH+kPY0EY1AzRMNQ==</DQ><InverseQ>Sxyz0fEf5m7GrzAngLDRP/i+QDikJFfM6qPyr3Ub6Y5RRsFbeOWY1tX3jmV31zv4cgJ6donH7W2dSBPi67sSsw==</InverseQ><D>nVqofsIgSZltxTcC8fA/DFz1kxMaFHKFvSK3RKIxQC1JQ3ASkUEYN/baAElB0f6u/oTNcNWVPOqE31IDe7ErQelVc4D26RgFd5V7dSsF3nVz00s4mq1qUBnCBLPIrdb0rcQZ8FUQTsd96qW8Foave4tm8vspbM65iVUBBVdSYYE=</D></RSAKeyValue>";
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
rsa.FromXmlString(pubkey);
RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsa);
f.SetHashAlgorithm("SHA1");
SHA1Managed sha = new SHA1Managed();
byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(toolcode));
byte[] key = Convert.FromBase64String(regcode);
return f.VerifySignature(name, key);
}
}
catch
{
return false;
}
}
示例6: Verify
public static bool Verify(Stream input, Stream output, string publicKey)
{
// ファイルから情報の抽出
var buffer = new byte[64];
if (input.Read(buffer, 0, 64) < 64)
throw new Exception("File is corrupted.(KSIG: Magic Not Found)");
var magicstr = Encoding.UTF8.GetString(buffer).Split(new[] { ":" }, StringSplitOptions.None);
if (magicstr.Length < 2)
throw new Exception("File is corrupted.(KSIG: Invalid Magic Length)");
if (magicstr[0] != MagicStr)
throw new Exception("File is corrupted.(KSIG: Invalid Magic String)");
var siglen = int.Parse(magicstr[1]);
var sigbuf = new byte[siglen];
if (input.Read(sigbuf, 0, siglen) < siglen)
throw new Exception("File is corrupted.(KSIG: Invalid Signature)");
var data = ReadAllBytes(input);
using (var sha = new SHA256Managed())
using (var rsa = new RSACryptoServiceProvider())
{
// Compute hash
var hash = sha.ComputeHash(data);
// RSA Initialize
rsa.FromXmlString(publicKey);
// deformat
var deformatter = new RSAPKCS1SignatureDeformatter(rsa);
deformatter.SetHashAlgorithm("SHA256");
if (!deformatter.VerifySignature(hash, sigbuf))
return false;
}
output.Write(data, 0, data.Length);
return true;
}
示例7: VerifySignature
public bool VerifySignature(byte[] hash, byte[] signedhash)
{
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAKeyInfo = new RSAParameters();
RSAKeyInfo.Modulus = m_public.Modulus;
RSAKeyInfo.Exponent = m_public.Exponent;
RSA.ImportParameters(RSAKeyInfo);
RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(RSA);
RSADeformatter.SetHashAlgorithm("MD5");
return RSADeformatter.VerifySignature(hash, signedhash);
}
示例8: VerifySignature
public bool VerifySignature(byte[] hashOfDataToSign, byte[] signature)
{
using (var rsa = new RSACryptoServiceProvider(2048))
{
rsa.ImportParameters(_publicKey);
var rsaDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
rsaDeformatter.SetHashAlgorithm("SHA256");
return rsaDeformatter.VerifySignature(hashOfDataToSign, signature);
}
}
示例9: VerifyString
/// <summary>
/// RSA验证
/// </summary>
/// <param name="CypherText">签名后的Base64字符串</param>
/// <param name="xmlString">密钥(至少含公钥)</param>
/// <param name="PlainText">原始串</param>
public static bool VerifyString(string CypherText, string xmlString, string PlainText)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(xmlString);
RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsa);
f.SetHashAlgorithm("SHA1");
SHA1Managed sha = new SHA1Managed();
byte[] bText = System.Convert.FromBase64String(CypherText);
byte[] bEnc = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(PlainText));
return f.VerifySignature(bEnc, bText);
}
示例10: ValidateSignature
public bool ValidateSignature(OAuthContext authContext, SigningContext signingContext)
{
if (signingContext.Algorithm == null) throw Error.AlgorithmPropertyNotSetOnSigningContext();
SHA1CryptoServiceProvider sha1 = GenerateHash(signingContext);
var deformatter = new RSAPKCS1SignatureDeformatter(signingContext.Algorithm);
deformatter.SetHashAlgorithm("MD5");
byte[] signature = Convert.FromBase64String(authContext.Signature);
return deformatter.VerifySignature(sha1, signature);
}
示例11: Verify
public bool Verify(byte[] signature, byte[] securedInput, object key)
{
using (var sha = HashAlgorithm)
{
var publicKey = Ensure.Type<AsymmetricAlgorithm>(key, "RsaUsingSha alg expects key to be of AsymmetricAlgorithm type.");
byte[] hash = sha.ComputeHash(securedInput);
var pkcs1 = new RSAPKCS1SignatureDeformatter(publicKey);
pkcs1.SetHashAlgorithm(hashMethod);
return pkcs1.VerifySignature(hash, signature);
}
}
示例12: Main
static void Main(string[] args)
{
string pubKey = ConfigurationManager.AppSettings["pubKey"];
string priKey = ConfigurationManager.AppSettings["priKey"];
string input = ConfigurationManager.AppSettings["input"];
string user = ConfigurationManager.AppSettings["user"];
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
SHA1Managed sha = new SHA1Managed();
rsa.FromXmlString(priKey);
Console.WriteLine("begin to encode:");
RSAPKCS1SignatureFormatter signFormatter = new RSAPKCS1SignatureFormatter(rsa);
signFormatter.SetHashAlgorithm("SHA1");
byte[] source = System.Text.ASCIIEncoding.UTF8.GetBytes(input);
byte[] result = sha.ComputeHash(source);
byte[] b = signFormatter.CreateSignature(result);
var signature = Convert.ToBase64String(b);
string outputFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sn", input + ".key");
FileInfo fi = new FileInfo(outputFile);
if (!fi.Directory.Exists)
{
fi.Directory.Create();
}
StreamWriter sw = new StreamWriter(fi.OpenWrite(), Encoding.UTF8);
sw.Write(signature);
sw.Close();
Console.WriteLine();
Console.WriteLine(signature);
using (RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider())
{
rsa2.FromXmlString(pubKey);
RSAPKCS1SignatureDeformatter decodeFormatter = new RSAPKCS1SignatureDeformatter(rsa2);
decodeFormatter.SetHashAlgorithm("SHA1");
byte[] key = Convert.FromBase64String(signature);
byte[] name = sha.ComputeHash(ASCIIEncoding.UTF8.GetBytes(input));
if (decodeFormatter.VerifySignature(name, key))
{
Console.WriteLine("===========can be decoded");
}
else
{
Console.WriteLine("===CANOT be decoded..................");
}
}
}
}
示例13: CheckSign
public bool CheckSign()
{
var signMsgVal = GetSign();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(signMsgVal);
byte[] SignatureByte = Convert.FromBase64String(signMsg);
var publicKey = CoreHelper.CustomSetting.GetConfigKey("快钱WEB公钥文件");
X509Certificate2 cert = new X509Certificate2(publicKey, "");
RSACryptoServiceProvider rsapri = (RSACryptoServiceProvider)cert.PublicKey.Key;
rsapri.ImportCspBlob(rsapri.ExportCspBlob(false));
RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsapri);
byte[] result;
f.SetHashAlgorithm("SHA1");
SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
result = sha.ComputeHash(bytes);
return f.VerifySignature(result, SignatureByte);
}
示例14: Validate
public bool Validate(string EncyptedBase64Key)
{
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
rsa.FromXmlString(pubkey);
RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsa);
f.SetHashAlgorithm("SHA1");
byte[] key = Convert.FromBase64String(pubkey);
SHA1Managed sha = new SHA1Managed();
byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(EncyptedBase64Key));
if (f.VerifySignature(name, key))
return true;
else
return false;
}
}
示例15: OnActionExecuting
public void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.HttpContext.User != null && (filterContext.HttpContext.User.Identity as ClaimsIdentity).Claims.Any())
{
var currentUserClaim = (filterContext.HttpContext.User.Identity as ClaimsIdentity).Claims.FirstOrDefault(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
if (currentUserClaim != null)
{
var currentUser = currentUserClaim.Value;
if (currentUser != null)
if (UserForLogOutDictionary.ContainsKey(currentUser))
{
FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie();
filterContext.HttpContext.Response.Redirect(UrlHelper.GenerateContentUrl("~/", filterContext.HttpContext));
filterContext.HttpContext.Response.End();
string temp;
UserForLogOutDictionary.TryRemove(currentUserClaim.Value, out temp);
}
}
}
var extendeduser = filterContext.HttpContext.Request.Form.Get("SAMLLogoutUser");
if (string.IsNullOrEmpty(extendeduser))
{
return;
}
var user = extendeduser.Split(";".ToCharArray())[0];
var issuer = HttpUtility.UrlDecode(extendeduser.Split(";".ToCharArray())[1]);
var signed = filterContext.HttpContext.Request.Form.Get("hash");
var cert = AuthServicesController.Options.IdentityProviders[new EntityId() { Id = issuer }];
RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(cert.SigningKeys.First());
RSADeformatter.SetHashAlgorithm("SHA1");
SHA1Managed SHhash = new SHA1Managed();
if (RSADeformatter.VerifySignature(
SHhash.ComputeHash(new UnicodeEncoding().GetBytes(HttpUtility.UrlEncode(extendeduser))),
System.Convert.FromBase64String(signed))
)
{
UserForLogOutDictionary[user] = "true";
return;
}
}