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


C# RSAPKCS1SignatureFormatter.SetKey方法代码示例

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


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

示例1: sign

 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);
     }
 }
开发者ID:s7loves,项目名称:pesta,代码行数:15,代码来源:RSA_SHA1.cs

示例2: CreateSignatureHash

		private byte[] CreateSignatureHash (string hashName) 
		{
			fmt = new RSAPKCS1SignatureFormatter ();

			// we need the private key 
			RSA rsa = RSA.Create ("Mono.Security.Cryptography.RSAManaged");	// only available with Mono::
			if (rsa == null) {
				rsa = RSA.Create ();
			}
			rsa.ImportParameters (AllTests.GetRsaKey (true));
			fmt.SetKey (rsa);

			HashAlgorithm hash = HashAlgorithm.Create (hashName);
			byte[] data = new byte [(hash.HashSize >> 3)];
			hash.ComputeHash (data);
			return fmt.CreateSignature (hash);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例3: SetKeyRSA

		public void SetKeyRSA () 
		{
			fmt = new RSAPKCS1SignatureFormatter ();
			fmt.SetKey (rsa);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例4: CreateSignatureRSABadHash

		public void CreateSignatureRSABadHash () 
		{
			fmt = new RSAPKCS1SignatureFormatter ();
			// we need the private key 
			fmt.SetKey (rsa);
			// null (bad ;-)
			byte[] hash = null;
			byte[] signature  = fmt.CreateSignature (hash);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例5: CreateSignatureHashMD5

		public void CreateSignatureHashMD5 () 
		{
			fmt = new RSAPKCS1SignatureFormatter ();
			byte[] data = new byte [16];
			// we need the private key 
			fmt.SetKey (rsa);
			// good MD5
			HashAlgorithm hash = MD5.Create ();
			hash.ComputeHash (data);
			byte[] signature = fmt.CreateSignature (hash);
			Assert.IsNotNull (signature);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例6: CreateSignatureRSAMD5

		public void CreateSignatureRSAMD5 () 
		{
			fmt = new RSAPKCS1SignatureFormatter ();
			// we need the private key 
			fmt.SetKey (rsa);
			// good MD5
			fmt.SetHashAlgorithm ("MD5");
			byte[] hash = new byte [16];
			byte[] signature = fmt.CreateSignature (hash);
			Assert.IsNotNull (fmt);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例7: CreateSignatureRSASHA1BadLength

		public void CreateSignatureRSASHA1BadLength () 
		{
			fmt = new RSAPKCS1SignatureFormatter ();
			// we need the private key 
			fmt.SetKey (rsa);
			// wrong length SHA1
			fmt.SetHashAlgorithm ("SHA1");
			byte[] hash = new byte [19];
			byte[] signature = fmt.CreateSignature (hash);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例8: CreateSignatureNullHash

		public void CreateSignatureNullHash () 
		{
			fmt = new RSAPKCS1SignatureFormatter ();
			fmt.SetKey (rsa);
			byte[] hash = null;
			byte[] signature = fmt.CreateSignature (hash);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例9: SetKeyNull

		public void SetKeyNull ()
		{
			fmt = new RSAPKCS1SignatureFormatter ();
			fmt.SetKey (null);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:RSAPKCS1SignatureFormatterTest.cs

示例10: Sign

		/// <summary>
		/// Signiert einen Text mit dem angegebenen privaten Schlüssel.
		/// </summary>
		/// <param name="textToSign">Der zusignierende Text.</param>
		/// <param name="privateKey">Der private Schlüssel.</param>
		/// <returns></returns>
		public static string Sign(string textToSign, string privateKey) {
			//Initialisieren der Provider
			var rsaCryptoServiceProvider = new RSACryptoServiceProvider();
			var rsaFormatter = new RSAPKCS1SignatureFormatter(rsaCryptoServiceProvider);
			System.Security.Cryptography.RSA rsa = System.Security.Cryptography.RSA.Create();
			var encoding = new ASCIIEncoding();
			var sha1 = new SHA1Managed();

			//Zuweisen des Hashalgorithmus und des privaten Schlüssels
			rsaFormatter.SetHashAlgorithm("SHA1");
			rsa.FromXmlString(privateKey);
			rsaFormatter.SetKey(rsa);

			//String nach Byte[] Konvertieren und die Signatur erstellen
			byte[] valueToHash = encoding.GetBytes(textToSign);
			byte[] signedValue = rsaFormatter.CreateSignature(sha1.ComputeHash(valueToHash));

			return Convert.ToBase64String(signedValue);
		}
开发者ID:Taipi88,项目名称:updateSystem.NET,代码行数:25,代码来源:RSA.cs


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