• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Cryptography.RandomNumberGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Security.Cryptography.RandomNumberGenerator的典型用法代码示例。如果您正苦于以下问题:C# RandomNumberGenerator类的具体用法?C# RandomNumberGenerator怎么用?C# RandomNumberGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RandomNumberGenerator类属于System.Security.Cryptography命名空间,在下文中一共展示了RandomNumberGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: 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);
 }
开发者ID:burris,项目名称:monotorrent,代码行数:10,代码来源:TokenManager.cs


示例17: Create

 internal static string Create(ref RandomNumberGenerator randgen)
 {
     if (randgen == null)
     {
         randgen = new RNGCryptoServiceProvider();
     }
     byte[] data = new byte[15];
     randgen.GetBytes(data);
     return Encode(data);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:10,代码来源:SessionId.cs


示例18: Spritz

        protected Spritz()
        {
#if !DOTNET5_4
            LegalBlockSizesValue = s_legalBlockSizes;
            LegalKeySizesValue = s_legalKeySizes;
#endif
            this.BlockSize = 256;
            this.KeySize = 128;
            this.rng = RandomNumberGenerator.Create();
        }
开发者ID:badmishkallc,项目名称:GoDark,代码行数:10,代码来源:Spritz.cs


示例19: Salsa20

        protected Salsa20()
        {
#if NET451
            LegalBlockSizesValue = s_legalBlockSizes;
            LegalKeySizesValue = s_legalKeySizes;
#endif
            this.BlockSize = 64;
            this.KeySize = 256;
            this.Rounds = Salsa20Rounds.Twenty;
            this.rng = RandomNumberGenerator.Create();
        }
开发者ID:badmishkallc,项目名称:GoDark,代码行数:11,代码来源:Salsa20.cs


示例20: CumulativeRandom

 public CumulativeRandom(int maxTimes)
 {
     rnd = RNGCryptoServiceProvider.Create();
     //rnd = new Random();
     basis = 1.0/maxTimes;
     buff = 0.0;
 }
开发者ID:Tilps,项目名称:Stash,代码行数:7,代码来源:CumulativeRandom.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cryptography.Rfc2898DeriveBytes类代码示例发布时间:2022-05-26
下一篇:
C# Cryptography.RSAParameters类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap