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


C# Cryptography.RandomNumberGenerator类代码示例

本文整理汇总了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;
 }
开发者ID:johnynek,项目名称:brunet,代码行数:10,代码来源:SecureRandom.cs

示例2: HashPasswordV3

 private byte[] HashPasswordV3(string password, RandomNumberGenerator rng) {
   return HashPasswordV3(password, rng,
     prf: KeyDerivationPrf.HMACSHA256,
     iterCount: _iterCount,
     saltSize: 128 / 8,
     numBytesRequested: 256 / 8);
 }
开发者ID:grrizzly,项目名称:eventsourced.net,代码行数:7,代码来源:PasswordHasher.cs

示例3: PasswordHasher

 private PasswordHasher() {
   _iterCount = 10000;
   if (_iterCount < 1) {
     throw new InvalidOperationException("InvalidPasswordHasherIterationCount");
   }
   _rng = RandomNumberGenerator.Create();
 }
开发者ID:grrizzly,项目名称:eventsourced.net,代码行数:7,代码来源:PasswordHasher.cs

示例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);
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:29,代码来源:SimpleFileDownloaderTest.cs

示例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;
 }
开发者ID:NikolayIT,项目名称:CSharp-Tips-and-Tricks,代码行数:7,代码来源:HighQualityRandomNumbers.cs

示例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);
 }
开发者ID:johnynek,项目名称:brunet,代码行数:11,代码来源:AHAddress.cs

示例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;
 }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:13,代码来源:SystemCrypto.cs

示例9: RNGCryptoServiceProvider

        public RNGCryptoServiceProvider(CspParameters cspParams)
        {
            if (cspParams != null)
                throw new PlatformNotSupportedException();

            // This class wraps RandomNumberGenerator.Create() from Algorithms assembly
            _impl = Create();
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:RNGCryptoServiceProvider.cs

示例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;
        }
开发者ID:Poyo-SSB,项目名称:MarkovioBot,代码行数:13,代码来源:RandomNumberGeneratorWrapper.cs

示例11: CryptoApiEntropySourceProvider

        public CryptoApiEntropySourceProvider(RandomNumberGenerator rng, bool isPredictionResistant)
        {
            if (rng == null)
                throw new ArgumentNullException("rng");

            mRng = rng;
            mPredictionResistant = isPredictionResistant;
        }
开发者ID:insthync,项目名称:bc-csharp,代码行数:8,代码来源:CryptoApiEntropySourceProvider.cs

示例12: IV

		static public byte[] IV (int size) 
		{
			if (rng == null)
				rng = RandomNumberGenerator.Create ();

			byte[] iv = new byte [size];
			rng.GetBytes (iv);
			return iv;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:CryptoTools.cs

示例13: PatchworkTransformService

 public PatchworkTransformService(
     RandomNumberGenerator randomNumberGenerator,
     byte delta = 4,
     int iterationNumber = 20000)
 {
     this._randomNumberGenerator = randomNumberGenerator;
     this._delta = delta;
     this._iterationNumber = iterationNumber;
 }
开发者ID:RamanBut-Husaim,项目名称:ZIRKSiS,代码行数:9,代码来源:PatchworkTransformService.cs

示例14: Key

		static public byte[] Key (int size) 
		{
			if (rng == null)
				rng = RandomNumberGenerator.Create ();

			byte[] key = new byte [size];
			rng.GetBytes (key);
			return key;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:CryptoTools.cs

示例15: GetRandom

        public static RandomNumberGenerator GetRandom()
        {
            if (_random == null)
            {
                _random = new RNGCryptoServiceProvider();
            }

            return _random;
        }
开发者ID:Joopie1994,项目名称:HabboEncryption,代码行数:9,代码来源:Randomizer.cs


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