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


C# RandomNumberGenerator.GetNonZeroBytes方法代码示例

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


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

示例1: TokenManager

 public TokenManager()
 {
     sha1 = HashAlgoFactory.Create<SHA1>();
     random = new RNGCryptoServiceProvider ();
     LastSecretGeneration = DateTime.MinValue; //in order to force the update
     secret = new byte[10];
     previousSecret = new byte[10];
     random.GetNonZeroBytes(secret);
     random.GetNonZeroBytes(previousSecret);
 }
开发者ID:dontnod,项目名称:monotorrent,代码行数:10,代码来源:TokenManager.cs

示例2: TokenManager

 public TokenManager()
 {
     sha1 = SHA1.Create();
     random = RandomNumberGenerator.Create();
     LastSecretGeneration = DateTime.MinValue; //in order to force the update
     secret = new byte[10];
     previousSecret = new byte[10];
     random.GetNonZeroBytes(secret);
     random.GetNonZeroBytes(previousSecret);
 }
开发者ID:burris,项目名称:monotorrent,代码行数:10,代码来源:TokenManager.cs

示例3: Encrypt_v15

		// PKCS #1 v.2.1, Section 7.2.1
		// RSAES-PKCS1-V1_5-ENCRYPT ((n, e), M)
		public static byte[] Encrypt_v15 (RSA rsa, RandomNumberGenerator rng, byte[] M) 
		{
			int size = rsa.KeySize / 8;
			if (M.Length > size - 11)
				throw new CryptographicException ("message too long");
			int PSLength = System.Math.Max (8, (size - M.Length - 3));
			byte[] PS = new byte [PSLength];
			rng.GetNonZeroBytes (PS);
			byte[] EM = new byte [size];
			EM [1] = 0x02;
			Buffer.BlockCopy (PS, 0, EM, 2, PSLength);
			Buffer.BlockCopy (M, 0, EM, (size - M.Length), M.Length);
	
			byte[] m = OS2IP (EM);
			byte[] c = RSAEP (rsa, m);
			byte[] C = I2OSP (c, size);
			return C;
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:20,代码来源:PKCS1.cs

示例4: EncryptPKCS1

	// Encrypt a value using the RSA public key and the PKCS1 encoding.
	internal byte[] EncryptPKCS1(byte[] rgb, RandomNumberGenerator rng)
			{
				// Check the data against null.
				if(rgb == null)
				{
					throw new ArgumentNullException("rgb");
				}

				// Make sure that we have sufficient RSA parameters.
				if(rsaParams.Modulus == null)
				{
					throw new CryptographicException
						(_("Crypto_RSAParamsNotSet"));
				}

				// Format the type codes, padding string, and data.
				int k = rsaParams.Modulus.Length;
				if(rgb.Length > (k - 11))
				{
					throw new CryptographicException
						(_("Crypto_RSAMessageTooLong"));
				}
				byte[] msg = new byte [k];
				msg[1] = (byte)0x02;
				byte[] padding = new byte [k - rgb.Length - 3];
				rng.GetNonZeroBytes(padding);
				Array.Copy(padding, 0, msg, 2, padding.Length);
				Array.Copy(rgb, 0, msg, k - rgb.Length, rgb.Length);

				// Encrypt the message.
				byte[] encrypted = ApplyPublic(msg);

				// Destroy sensitive data.
				Array.Clear(msg, 0, msg.Length);
				Array.Clear(padding, 0, padding.Length);

				// Done.
				return encrypted;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:40,代码来源:RSACryptoServiceProvider.cs


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