當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。