本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}