up
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
|
||||
|
||||
using System;
|
||||
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using Org.BouncyCastle.Math;
|
||||
|
||||
namespace Org.BouncyCastle.Crypto.Generators
|
||||
{
|
||||
/**
|
||||
* a basic Diffie-Hellman key pair generator.
|
||||
*
|
||||
* This generates keys consistent for use with the basic algorithm for
|
||||
* Diffie-Hellman.
|
||||
*/
|
||||
public class DHBasicKeyPairGenerator
|
||||
: IAsymmetricCipherKeyPairGenerator
|
||||
{
|
||||
private DHKeyGenerationParameters param;
|
||||
|
||||
public virtual void Init(
|
||||
KeyGenerationParameters parameters)
|
||||
{
|
||||
this.param = (DHKeyGenerationParameters)parameters;
|
||||
}
|
||||
|
||||
public virtual AsymmetricCipherKeyPair GenerateKeyPair()
|
||||
{
|
||||
DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.Instance;
|
||||
DHParameters dhp = param.Parameters;
|
||||
|
||||
BigInteger x = helper.CalculatePrivate(dhp, param.Random);
|
||||
BigInteger y = helper.CalculatePublic(dhp, x);
|
||||
|
||||
return new AsymmetricCipherKeyPair(
|
||||
new DHPublicKeyParameters(y, dhp),
|
||||
new DHPrivateKeyParameters(x, dhp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user