System.Security.Cryptography.RSAPKCS1SignatureFormatter.SetKey C# (CSharp) Method

SetKey() public method

public SetKey ( AsymmetricAlgorithm key ) : void
key AsymmetricAlgorithm
return void
		public override void SetKey (AsymmetricAlgorithm key) 
		{
#if NET_2_0
			if (key == null)
				throw new ArgumentNullException ("key");
#else
			// 1.0/1.1 accepted null without an ArgumentNullException!
#endif
			rsa = (RSA) key;
		}
	}

Usage Example

Example #1
0
 private byte[] sign(byte[] message)
 {
     if (certificate.PrivateKey == null)
     {
         throw new Exception("a private key is required when generating RSA-SHA1 signatures.");
     }
     using (HashAlgorithm hasher = HashAlgorithm.Create("SHA1"))
     {
         RSAPKCS1SignatureFormatter signatureFormatter = new RSAPKCS1SignatureFormatter();
         signatureFormatter.SetKey(certificate.PrivateKey);
         signatureFormatter.SetHashAlgorithm("SHA1");
         byte[] hash = hasher.ComputeHash(message);
         return signatureFormatter.CreateSignature(hash);
     }
 }
All Usage Examples Of System.Security.Cryptography.RSAPKCS1SignatureFormatter::SetKey