本文整理匯總了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;
}