本文整理汇总了C#中System.Security.Cryptography.RandomNumberGenerator类的典型用法代码示例。如果您正苦于以下问题:C# RandomNumberGenerator类的具体用法?C# RandomNumberGenerator怎么用?C# RandomNumberGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RandomNumberGenerator类属于System.Security.Cryptography命名空间,在下文中一共展示了RandomNumberGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SecureRandom
/**
* Create a System.Random object from this RandomNumberGenerator
*/
public SecureRandom(RandomNumberGenerator rng) {
_rng = rng;
_sample_buffer = new byte[4];
_state = new Sample();
_state.Val = 0;
_state.Max = 1;
}
示例2: HashPasswordV3
private byte[] HashPasswordV3(string password, RandomNumberGenerator rng) {
return HashPasswordV3(password, rng,
prf: KeyDerivationPrf.HMACSHA256,
iterCount: _iterCount,
saltSize: 128 / 8,
numBytesRequested: 256 / 8);
}
示例3: PasswordHasher
private PasswordHasher() {
_iterCount = 10000;
if (_iterCount < 1) {
throw new InvalidOperationException("InvalidPasswordHasherIterationCount");
}
_rng = RandomNumberGenerator.Create();
}
示例4: CreateKeyExchange
public override byte[] CreateKeyExchange(byte[] rgbData)
{
if (this._rsaKey == null)
{
throw new CryptographicUnexpectedOperationException(Environment.GetResourceString("Cryptography_MissingKey"));
}
if (this._rsaKey is RSACryptoServiceProvider)
{
return ((RSACryptoServiceProvider) this._rsaKey).Encrypt(rgbData, false);
}
int num = this._rsaKey.KeySize / 8;
if ((rgbData.Length + 11) > num)
{
throw new CryptographicException(Environment.GetResourceString("Cryptography_Padding_EncDataTooBig", new object[] { num - 11 }));
}
byte[] data = new byte[num];
if (this.RngValue == null)
{
this.RngValue = RandomNumberGenerator.Create();
}
this.Rng.GetNonZeroBytes(data);
data[0] = 0;
data[1] = 2;
data[(num - rgbData.Length) - 1] = 0;
Buffer.InternalBlockCopy(rgbData, 0, data, num - rgbData.Length, rgbData.Length);
return this._rsaKey.EncryptValue(data);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:RSAPKCS1KeyExchangeFormatter.cs
示例5: SetUp
private void SetUp(long length) {
this.transmission = new Transmission(TransmissionType.DOWNLOAD_NEW_FILE, "testfile");
this.transmission.AddDefaultConstraints();
if (this.localFileStream != null) {
this.localFileStream.Dispose();
}
this.localFileStream = new MemoryStream();
if (this.hashAlg != null) {
this.hashAlg.Dispose();
}
this.hashAlg = new SHA1Managed();
this.remoteLength = length;
this.remoteContent = new byte[this.remoteLength];
if (this.random != null) {
this.random.Dispose();
}
this.random = RandomNumberGenerator.Create();
this.random.GetBytes(this.remoteContent);
this.mockedMemStream = new Mock<MemoryStream>(this.remoteContent) { CallBase = true };
this.mockedStream = new Mock<IContentStream>();
this.mockedStream.Setup(stream => stream.Length).Returns(this.remoteLength);
this.mockedStream.Setup(stream => stream.Stream).Returns(this.mockedMemStream.Object);
this.mockedDocument = new Mock<IDocument>();
this.mockedDocument.Setup(doc => doc.ContentStreamLength).Returns(this.remoteLength);
this.mockedDocument.Setup(doc => doc.GetContentStream()).Returns(this.mockedStream.Object);
}
示例6: GenerateRandomInt32Value
private static int GenerateRandomInt32Value(RandomNumberGenerator randomNumberGenerator)
{
var fourRandomBytes = new byte[4]; // 4 bytes = 32 bits = Int32
randomNumberGenerator.GetBytes(fourRandomBytes);
var randomInt32Value = BitConverter.ToInt32(fourRandomBytes, 0);
return randomInt32Value;
}
示例7: AHAddress
/**
* Return a random AHAddress initialized from the given rng
*/
public AHAddress(RandomNumberGenerator rng)
{
byte[] buffer = new byte[MemSize];
rng.GetBytes(buffer);
SetClass(buffer, this.Class);
_buffer = MemBlock.Reference(buffer, 0, MemSize);
_prefix = (uint)NumberSerializer.ReadInt(_buffer, 0);
}
示例8: SystemCryptoRandomNumberGenerator
/// <summary>
/// Construct a new random number generator with random seed.
/// </summary>
/// <param name="rng">The <see cref="RandomNumberGenerator"/> to use.</param>
/// <param name="threadSafe">if set to <c>true</c> , the class is thread safe.</param>
public SystemCryptoRandomNumberGenerator(RandomNumberGenerator rng, bool threadSafe) : base(threadSafe)
{
if (rng == null)
{
throw new ArgumentNullException("rng");
}
mRandom = rng;
}
示例9: RNGCryptoServiceProvider
public RNGCryptoServiceProvider(CspParameters cspParams)
{
if (cspParams != null)
throw new PlatformNotSupportedException();
// This class wraps RandomNumberGenerator.Create() from Algorithms assembly
_impl = Create();
}
示例10: RandomNumberGeneratorWrapper
/// <summary>
/// Initializes a new instance of the RandomNumberGeneratorWrapper class, wrapping a given <see cref="System.Security.Cryptography.RandomNumberGenerator"/> instance.
/// </summary>
/// <param name="rand">The instance of <see cref="System.Security.Cryptography.RandomNumberGenerator"/> to wrap.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="rand"/> is null.</exception>
public RandomNumberGeneratorWrapper(RandomNumberGenerator rand)
{
if (rand == null) {
throw new ArgumentNullException("rand");
}
this.rand = rand;
}
示例11: CryptoApiEntropySourceProvider
public CryptoApiEntropySourceProvider(RandomNumberGenerator rng, bool isPredictionResistant)
{
if (rng == null)
throw new ArgumentNullException("rng");
mRng = rng;
mPredictionResistant = isPredictionResistant;
}
示例12: IV
static public byte[] IV (int size)
{
if (rng == null)
rng = RandomNumberGenerator.Create ();
byte[] iv = new byte [size];
rng.GetBytes (iv);
return iv;
}
示例13: PatchworkTransformService
public PatchworkTransformService(
RandomNumberGenerator randomNumberGenerator,
byte delta = 4,
int iterationNumber = 20000)
{
this._randomNumberGenerator = randomNumberGenerator;
this._delta = delta;
this._iterationNumber = iterationNumber;
}
示例14: Key
static public byte[] Key (int size)
{
if (rng == null)
rng = RandomNumberGenerator.Create ();
byte[] key = new byte [size];
rng.GetBytes (key);
return key;
}
示例15: GetRandom
public static RandomNumberGenerator GetRandom()
{
if (_random == null)
{
_random = new RNGCryptoServiceProvider();
}
return _random;
}