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


C# Security.SecureRandom类代码示例

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


SecureRandom类属于Org.BouncyCastle.Security命名空间,在下文中一共展示了SecureRandom类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DsaKeyGenerationParameters

        public DsaKeyGenerationParameters(
            SecureRandom	random,
            DsaParameters	parameters)
			: base(random, parameters.P.BitLength - 1)
        {
            this.parameters = parameters;
        }
开发者ID:MBrekhof,项目名称:pleiobox-clients,代码行数:7,代码来源:DsaKeyGenerationParameters.cs

示例2: ECKeyGenerationParameters

		public ECKeyGenerationParameters(
			ECDomainParameters	domainParameters,
			SecureRandom		random)
			: base(random, domainParameters.N.BitLength)
        {
            this.domainParams = domainParameters;
        }
开发者ID:nicecai,项目名称:iTextSharp-4.1.6,代码行数:7,代码来源:ECKeyGenerationParameters.cs

示例3: Init

        public void Init(
			bool				forSigning,
			ICipherParameters	parameters)
        {
            if (forSigning)
            {
                if (parameters is ParametersWithRandom)
                {
                    ParametersWithRandom rParam = (ParametersWithRandom)parameters;

                    this.random = rParam.Random;
            //					this.key = (Gost3410PrivateKeyParameters)rParam.Parameters;
                    parameters = rParam.Parameters;
                }
                else
                {
                    this.random = new SecureRandom();
            //					this.key = (Gost3410PrivateKeyParameters)parameters;
                }

                if (!(parameters is Gost3410PrivateKeyParameters))
                    throw new InvalidKeyException("GOST3410 private key required for signing");

                this.key = (Gost3410PrivateKeyParameters) parameters;
            }
            else
            {
                if (!(parameters is Gost3410PublicKeyParameters))
                    throw new InvalidKeyException("GOST3410 public key required for signing");

                this.key = (Gost3410PublicKeyParameters) parameters;
            }
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:33,代码来源:GOST3410Signer.cs

示例4: Init

		public void Init(
			ICipherParameters parameters)
		{
			AsymmetricKeyParameter kParam;
			if (parameters is ParametersWithRandom)
			{
				ParametersWithRandom rParam = (ParametersWithRandom)parameters;

				this.random = rParam.Random;
				kParam = (AsymmetricKeyParameter)rParam.Parameters;
			}
			else
			{
				this.random = new SecureRandom();
				kParam = (AsymmetricKeyParameter)parameters;
			}

			if (!(kParam is DHPrivateKeyParameters))
			{
				throw new ArgumentException("DHEngine expects DHPrivateKeyParameters");
			}

			this.key = (DHPrivateKeyParameters)kParam;
			this.dhParams = key.Parameters;
		}
开发者ID:htlp,项目名称:itextsharp,代码行数:25,代码来源:DHAgreement.cs

示例5: CreateRandomInRange

        /**
        * Return a random BigInteger not less than 'min' and not greater than 'max'
        * 
        * @param min the least value that may be generated
        * @param max the greatest value that may be generated
        * @param random the source of randomness
        * @return a random BigInteger value in the range [min,max]
        */
        public static BigInteger CreateRandomInRange(
            BigInteger		min,
            BigInteger		max,
            // TODO Should have been just Random class
            SecureRandom	random)
        {
            int cmp = min.CompareTo(max);
            if (cmp >= 0)
            {
                if (cmp > 0)
                    throw new ArgumentException("'min' may not be greater than 'max'");

                return min;
            }

            if (min.BitLength > max.BitLength / 2)
            {
                return CreateRandomInRange(BigInteger.Zero, max.Subtract(min), random).Add(min);
            }

            for (int i = 0; i < MaxIterations; ++i)
            {
                BigInteger x = new BigInteger(max.BitLength, random);
                if (x.CompareTo(min) >= 0 && x.CompareTo(max) <= 0)
                {
                    return x;
                }
            }

            // fall back to a faster (restricted) method
            return new BigInteger(max.Subtract(min).BitLength - 1, random).Add(min);
        }
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:40,代码来源:BigIntegers.cs

示例6: Init

	    /**
	     * Initialises the client to begin new authentication attempt
	     * @param N The safe prime associated with the client's verifier
	     * @param g The group parameter associated with the client's verifier
	     * @param digest The digest algorithm associated with the client's verifier
	     * @param random For key generation
	     */
	    public virtual void Init(BigInteger N, BigInteger g, IDigest digest, SecureRandom random)
	    {
	        this.N = N;
	        this.g = g;
	        this.digest = digest;
	        this.random = random;
	    }
开发者ID:htlp,项目名称:itextsharp,代码行数:14,代码来源:SRP6Client.cs

示例7: InitSign

		/// <summary>Initialise the generator for signing.</summary>
		public void InitSign(
			int				sigType,
			PgpPrivateKey	key,
			SecureRandom	random)
		{
			this.privKey = key;
			this.signatureType = sigType;

			try
			{
				ICipherParameters cp = key.Key;
				if (random != null)
				{
					cp = new ParametersWithRandom(key.Key, random);
				}

				sig.Init(true, cp);
			}
			catch (InvalidKeyException e)
			{
				throw new PgpException("invalid key.", e);
			}

			dig.Reset();
			lastb = 0;
		}
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:27,代码来源:PgpSignatureGenerator.cs

示例8: DtlsProtocol

        protected DtlsProtocol(SecureRandom secureRandom)
        {
            if (secureRandom == null)
                throw new ArgumentNullException("secureRandom");

            this.mSecureRandom = secureRandom;
        }
开发者ID:rodrigobrito,项目名称:bc-csharp,代码行数:7,代码来源:DtlsProtocol.cs

示例9: Init

        public virtual void Init(bool forSigning, ICipherParameters	parameters)
        {
            SecureRandom providedRandom = null;

            if (forSigning)
            {
                if (parameters is ParametersWithRandom)
                {
                    ParametersWithRandom rParam = (ParametersWithRandom)parameters;

                    providedRandom = rParam.Random;
                    parameters = rParam.Parameters;
                }

                if (!(parameters is DsaPrivateKeyParameters))
                    throw new InvalidKeyException("DSA private key required for signing");

                this.key = (DsaPrivateKeyParameters)parameters;
            }
            else
            {
                if (!(parameters is DsaPublicKeyParameters))
                    throw new InvalidKeyException("DSA public key required for verification");

                this.key = (DsaPublicKeyParameters)parameters;
            }

            this.random = InitSecureRandom(forSigning && !kCalculator.IsDeterministic, providedRandom);
        }
开发者ID:JohnMalmsteen,项目名称:mobile-apps-tower-defense,代码行数:29,代码来源:DsaSigner.cs

示例10: GenerateEncryptedPreMasterSecret

		public static byte[] GenerateEncryptedPreMasterSecret(SecureRandom random,
			RsaKeyParameters rsaServerPublicKey, Stream output)
		{
			/*
			 * Choose a PremasterSecret and send it encrypted to the server
			 */
			byte[] premasterSecret = new byte[48];
			random.NextBytes(premasterSecret);
			TlsUtilities.WriteVersion(premasterSecret, 0);

			Pkcs1Encoding encoding = new Pkcs1Encoding(new RsaBlindedEngine());
			encoding.Init(true, new ParametersWithRandom(rsaServerPublicKey, random));

			try
			{
				byte[] keData = encoding.ProcessBlock(premasterSecret, 0, premasterSecret.Length);
                TlsUtilities.WriteOpaque16(keData, output);
			}
			catch (InvalidCipherTextException)
			{
				/*
				* This should never happen, only during decryption.
				*/
				throw new TlsFatalAlert(AlertDescription.internal_error);
			}

			return premasterSecret;
		}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:28,代码来源:TlsRsaUtilities.cs

示例11: X931SecureRandom

 internal X931SecureRandom(SecureRandom randomSource, X931Rng drbg, bool predictionResistant)
     : base((IRandomGenerator)null)
 {
     this.mRandomSource = randomSource;
     this.mDrbg = drbg;
     this.mPredictionResistant = predictionResistant;
 }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:7,代码来源:X931SecureRandom.cs

示例12: CalculatePrivate

		internal BigInteger CalculatePrivate(
			DHParameters	dhParams,
			SecureRandom	random)
		{
			int limit = dhParams.L;

			if (limit != 0)
			{
				return new BigInteger(limit, random).SetBit(limit - 1);
			}

			BigInteger min = BigInteger.Two;
			int m = dhParams.M;
			if (m != 0)
			{
				min = BigInteger.One.ShiftLeft(m - 1);
			}

			BigInteger max = dhParams.P.Subtract(BigInteger.Two);
			BigInteger q = dhParams.Q;
			if (q != null)
			{
				max = q.Subtract(BigInteger.Two);
			}

			return BigIntegers.CreateRandomInRange(min, max, random);
		}
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:27,代码来源:DHKeyGeneratorHelper.cs

示例13: DHKeyGenerationParameters

		public DHKeyGenerationParameters(
            SecureRandom	random,
            DHParameters	parameters)
			: base(random, GetStrength(parameters))
        {
            this.parameters = parameters;
        }
开发者ID:JohnMalmsteen,项目名称:mobile-apps-tower-defense,代码行数:7,代码来源:DHKeyGenerationParameters.cs

示例14: CalculateRawSignature

        public virtual byte[] CalculateRawSignature(SecureRandom random,
			IAsymmetricKeyParameter privateKey, byte[] md5andsha1)
        {
            ISigner s = MakeSigner(new NullDigest(), true, new ParametersWithRandom(privateKey, random));
            s.BlockUpdate(md5andsha1, 0, md5andsha1.Length);
            return s.GenerateSignature();
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:7,代码来源:TlsRsaSigner.cs

示例15: TspTestUtil

		static TspTestUtil()
		{
			rand = new SecureRandom();

			kpg = GeneratorUtilities.GetKeyPairGenerator("RSA");
			kpg.Init(new RsaKeyGenerationParameters(
				BigInteger.ValueOf(0x10001), rand, 1024, 25));

			desede128kg = GeneratorUtilities.GetKeyGenerator("DESEDE");
			desede128kg.Init(new KeyGenerationParameters(rand, 112));

			desede192kg = GeneratorUtilities.GetKeyGenerator("DESEDE");
			desede192kg.Init(new KeyGenerationParameters(rand, 168));

			rc240kg = GeneratorUtilities.GetKeyGenerator("RC2");
			rc240kg.Init(new KeyGenerationParameters(rand, 40));

			rc264kg = GeneratorUtilities.GetKeyGenerator("RC2");
			rc264kg.Init(new KeyGenerationParameters(rand, 64));

			rc2128kg = GeneratorUtilities.GetKeyGenerator("RC2");
			rc2128kg.Init(new KeyGenerationParameters(rand, 128));

			serialNumber = BigInteger.One;
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:25,代码来源:TSPTestUtil.cs


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