本文整理汇总了C#中Org.BouncyCastle.Crypto.Parameters.DHParameters类的典型用法代码示例。如果您正苦于以下问题:C# DHParameters类的具体用法?C# DHParameters怎么用?C# DHParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DHParameters类属于Org.BouncyCastle.Crypto.Parameters命名空间,在下文中一共展示了DHParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculatePrivate
internal IBigInteger CalculatePrivate(
DHParameters dhParams,
ISecureRandom random)
{
int limit = dhParams.L;
if (limit != 0)
{
return new BigInteger(limit, random).SetBit(limit - 1);
}
IBigInteger min = BigInteger.Two;
int m = dhParams.M;
if (m != 0)
{
min = BigInteger.One.ShiftLeft(m - 1);
}
IBigInteger max = dhParams.P.Subtract(BigInteger.Two);
IBigInteger q = dhParams.Q;
if (q != null)
{
max = q.Subtract(BigInteger.Two);
}
return BigIntegers.CreateRandomInRange(min, max, random);
}
示例2: ComputeSharedSecret
public static BigInteger ComputeSharedSecret(string A, AsymmetricKeyParameter bPrivateKey, DHParameters internalParameters)
{
var importedKey = new DHPublicKeyParameters(new BigInteger(A), internalParameters);
var internalKeyAgree = AgreementUtilities.GetBasicAgreement("DH");
internalKeyAgree.Init(bPrivateKey);
return internalKeyAgree.CalculateAgreement(importedKey);
}
示例3: GenerateKeys
public static AsymmetricCipherKeyPair GenerateKeys(DHParameters parameters)
{
var keyGen = GeneratorUtilities.GetKeyPairGenerator("DH");
var kgp = new DHKeyGenerationParameters(new SecureRandom(), parameters);
keyGen.Init(kgp);
return keyGen.GenerateKeyPair();
}
示例4: DHKeyGenerationParameters
public DHKeyGenerationParameters(
SecureRandom random,
DHParameters parameters)
: base(random, GetStrength(parameters))
{
this.parameters = parameters;
}
示例5: DHKeyGenerationParameters
public DHKeyGenerationParameters(
SecureRandom random,
DHParameters parameters)
: base(random, parameters.P.BitLength)
{
this.parameters = parameters;
}
示例6: DHPrivateKeyParameters
public DHPrivateKeyParameters(
BigInteger x,
DHParameters parameters)
: base(true, parameters)
{
this.x = x;
}
示例7: DHKeyParameters
protected DHKeyParameters(
bool isPrivate,
DHParameters parameters)
: base(isPrivate)
{
// TODO Should we allow parameters to be null?
this.parameters = parameters;
}
示例8: DHPublicKeyParameters
public DHPublicKeyParameters(
BigInteger y,
DHParameters parameters)
: base(false, parameters)
{
if (y == null)
throw new ArgumentNullException("y");
this.y = y;
}
示例9: DHKeyParameters
protected DHKeyParameters(
bool isPrivate,
DHParameters parameters,
DerObjectIdentifier algorithmOid)
: base(isPrivate)
{
// TODO Should we allow parameters to be null?
this.parameters = parameters;
this.algorithmOid = algorithmOid;
}
示例10: DHProvider
public DHProvider(DHParameters parameters)
{
_parameters = parameters;
IAsymmetricCipherKeyPairGenerator keyGen = GeneratorUtilities.GetKeyPairGenerator("DH");
KeyGenerationParameters kgp = new DHKeyGenerationParameters(new SecureRandom(), _parameters);
keyGen.Init(kgp);
_kp = keyGen.GenerateKeyPair();
}
示例11: DHPublicKeyParameters
public DHPublicKeyParameters(
BigInteger y,
DHParameters parameters,
DerObjectIdentifier algorithmOid)
: base(false, parameters, algorithmOid)
{
if (y == null)
throw new ArgumentNullException("y");
this.y = y;
}
示例12: ServerAuthority
public ServerAuthority(DHParameters parameters)
{
this.parameters = parameters;
IAsymmetricCipherKeyPairGenerator keyGen = GeneratorUtilities.GetKeyPairGenerator("DH");
KeyGenerationParameters kgp = new DHKeyGenerationParameters(new SecureRandom(), parameters);
keyGen.Init(kgp);
kp = keyGen.GenerateKeyPair();
agreement = AgreementUtilities.GetBasicAgreement("DH");
agreement.Init(kp.Private);
}
示例13: GenerateEphemeralClientKeyExchange
public static DHPrivateKeyParameters GenerateEphemeralClientKeyExchange(SecureRandom random,
DHParameters dhParams, Stream output)
{
AsymmetricCipherKeyPair dhAgreeClientKeyPair = GenerateDHKeyPair(random, dhParams);
DHPrivateKeyParameters dhAgreeClientPrivateKey =
(DHPrivateKeyParameters)dhAgreeClientKeyPair.Private;
BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.Public).Y;
byte[] keData = BigIntegers.AsUnsignedByteArray(Yc);
TlsUtilities.WriteOpaque16(keData, output);
return dhAgreeClientPrivateKey;
}
示例14: GenerateKeyPair
public AsymmetricCipherKeyPair GenerateKeyPair()
{
DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.Instance;
ElGamalParameters egp = param.Parameters;
DHParameters dhp = new DHParameters(egp.P, egp.G, null, 0, egp.L);
BigInteger x = helper.CalculatePrivate(dhp, param.Random);
BigInteger y = helper.CalculatePublic(dhp, x);
return new AsymmetricCipherKeyPair(
new ElGamalPublicKeyParameters(y, egp),
new ElGamalPrivateKeyParameters(x, egp));
}
示例15: Mix
/// <summary>
/// Create a Diffie-Hellman key pair mixture.
/// </summary>
/// <returns>KeyPair mixture</returns>
public KeyPair Mix()
{
var cipherKeyPairGenerator = GeneratorUtilities.GetKeyPairGenerator("DiffieHellman");
var diffieHellmanParameters = new DHParameters(_common.P, _common.G, null);
KeyGenerationParameters diffieHellmanKeyGenerationParameters = new DHKeyGenerationParameters(new Org.BouncyCastle.Security.SecureRandom(), diffieHellmanParameters);
cipherKeyPairGenerator.Init(diffieHellmanKeyGenerationParameters);
var asymmetricKeyPair = cipherKeyPairGenerator.GenerateKeyPair();
var agreement = AgreementUtilities.GetBasicAgreement("DiffieHellman");
agreement.Init(asymmetricKeyPair.Private);
return new KeyPair() { Private = ((DHPrivateKeyParameters)asymmetricKeyPair.Private).X.ToString(), Public = ((DHPublicKeyParameters)asymmetricKeyPair.Public).Y.ToString() };
}