本文整理汇总了C#中System.Security.Cryptography.RSAPKCS1SignatureDeformatter.SetKey方法的典型用法代码示例。如果您正苦于以下问题:C# RSAPKCS1SignatureDeformatter.SetKey方法的具体用法?C# RSAPKCS1SignatureDeformatter.SetKey怎么用?C# RSAPKCS1SignatureDeformatter.SetKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.RSAPKCS1SignatureDeformatter
的用法示例。
在下文中一共展示了RSAPKCS1SignatureDeformatter.SetKey方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetNullKey
public void SetNullKey ()
{
RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter ();
fmt.SetKey (null);
}
示例2: GetDefaultDeformatter
private RSAPKCS1SignatureDeformatter GetDefaultDeformatter (string hashName)
{
// no need for the private key
RSA rsa = RSA.Create ();
rsa.ImportParameters (AllTests.GetRsaKey (false));
RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter ();
fmt.SetKey (rsa);
fmt.SetHashAlgorithm (hashName);
return fmt;
}
示例3: SetDSAKey
public void SetDSAKey ()
{
RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter ();
fmt.SetKey (dsa);
}
示例4: VerifySignatureNullSignature
public void VerifySignatureNullSignature ()
{
RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter ();
fmt.SetHashAlgorithm ("SHA1");
fmt.SetKey (rsa);
byte[] hash = new byte [20];
fmt.VerifySignature (hash, null);
}
示例5: VerifySignatureWithBadHash
public void VerifySignatureWithBadHash ()
{
RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter ();
fmt.SetKey (rsa);
// no hash algorithm
byte[] hash = new byte [1];
byte[] signature = new byte [1];
fmt.VerifySignature (hash, signature);
}
示例6: VerifySignatureNullHash
public void VerifySignatureNullHash ()
{
RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter ();
fmt.SetHashAlgorithm ("SHA1");
fmt.SetKey (rsa);
byte[] hash = null;
byte[] signature = new byte [128];
fmt.VerifySignature (hash, signature);
}
示例7: verify
private bool verify(byte[] signature, byte[] message)
{
if (certificate.PublicKey == null)
{
throw new Exception("a public key is required " +
" OAuthConsumer.setProperty when " +
"verifying RSA-SHA1 signatures.");
}
using (HashAlgorithm hasher = HashAlgorithm.Create("SHA1"))
{
RSAPKCS1SignatureDeformatter signatureDeformatter = new RSAPKCS1SignatureDeformatter(certificate.PrivateKey);
signatureDeformatter.SetKey(certificate.PublicKey.Key);
signatureDeformatter.SetHashAlgorithm("SHA1");
byte[] hash = hasher.ComputeHash(message);
return signatureDeformatter.VerifySignature(hash, signature);
}
}
示例8: IsValidSignature
/// <summary>
/// Confirms the validity of the OAuth request signature.
/// </summary>
/// <param name="uri">URI of the resource.</param>
/// <param name="httpMethod">Request method.</param>
/// <param name="arguments">Request arguments.</param>
/// <param name="consumerSecret">Consumer secret.</param>
/// <param name="tokenSecret">Token secret.</param>
/// <param name="rsaCert">For RSA-SHA1 signing, the X509 certificate containing the public key used to verify the signature.</param>
/// <returns>True if the signature is valid, false if not.</returns>
static bool IsValidSignature(Uri uri, string httpMethod, NameValueCollection arguments, string consumerSecret, string tokenSecret, X509Certificate2 rsaCert)
{
NameValueCollection args = new NameValueCollection(arguments);
string receivedsig = args[OAuthArguments.OAuthSignature];
args.Remove(OAuthArguments.OAuthSignature);
string sigMethod = args[OAuthArguments.OAuthSignatureMethod];
args.Remove(Strings.Realm);
string basestring = OAuthUtility.GenerateBaseString(uri, args, httpMethod);
if (OAuthUtility.StringToSigMethod(sigMethod) == SignatureMethod.RsaSha1)
{
RSAPKCS1SignatureDeformatter verifier = new RSAPKCS1SignatureDeformatter();
verifier.SetKey(rsaCert.PublicKey.Key);
verifier.SetHashAlgorithm("SHA1");
byte[] input = Encoding.UTF8.GetBytes(basestring);
byte[] hash = SHA1.Create().ComputeHash(input);
byte[] sig = Convert.FromBase64String(receivedsig);
return verifier.VerifySignature(hash, sig);
}
else
{
string calcsig = OAuthUtility.GenerateSignature(basestring, consumerSecret, tokenSecret, null, OAuthUtility.StringToSigMethod(sigMethod));
if (receivedsig == calcsig) { return true; }
}
return false;
}
示例9: validateSign
/// <summary>
/// Validiert einen signierten String
/// </summary>
/// <param name="textToValidate">Der unsignierte Text welcher mit der Signatur überprüft werden soll.</param>
/// <param name="signToValidate">Die Signatur des Textes.</param>
/// <param name="publicKey">Der öffentliche Schlüssel.</param>
/// <returns></returns>
public static bool validateSign(string textToValidate, string signToValidate, string publicKey) {
//Initialisieren der Provider
var rsacryptoprov = new RSACryptoServiceProvider();
var rsaDeFormatter = new RSAPKCS1SignatureDeformatter(rsacryptoprov);
System.Security.Cryptography.RSA rsa = System.Security.Cryptography.RSA.Create();
var sha1 = new SHA1Managed();
var encoding = new ASCIIEncoding();
//Zuweisen des Hashalgorithmus und des öffentlichen Schlüssels
rsaDeFormatter.SetHashAlgorithm("SHA1");
rsa.FromXmlString(publicKey);
rsaDeFormatter.SetKey(rsa);
//String nach Byte[]
byte[] hashed_value = encoding.GetBytes(textToValidate);
byte[] signed_value = Convert.FromBase64String(signToValidate);
//Signatur validieren und wert zurückgeben true/false
return rsaDeFormatter.VerifySignature(sha1.ComputeHash(hashed_value), signed_value);
}
示例10: Verify
/// <summary>
/// Verify a signature.
/// Throws only on unexpected failures.
/// </summary>
/// <param name="data">Data, utf8</param>
/// <param name="signature">Signature, base64</param>
/// <returns>True or false (or throws)</returns>
public static bool Verify(string data, string signature)
{
// Construct the cert
byte[] certdata = new System.Text.ASCIIEncoding().GetBytes(CERT);
byte[] rawdata = Encoding.UTF8.GetBytes(data);
// Compute hash of the raw data.
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] contenthash = sha.ComputeHash(rawdata);
// Base64-decode the signature
int sl = (signature.Length % 4);
if(sl>0)
for (int j = 0; j < 4-sl; j++) { signature += "="; }
byte[] sigdata = Convert.FromBase64String(signature);
bool ok = false;
X509Certificate2 cert = new X509Certificate2(certdata);
RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter();
RSADeformatter.SetHashAlgorithm("SHA1");
RSADeformatter.SetKey(cert.PublicKey.Key);
ok=RSADeformatter.VerifySignature(contenthash, sigdata);
return ok;
}