/// <summary> /// Inits the instance for encryption. /// </summary> /// <param name="privateKey">The private key.</param> /// <param name="publicKey">The public key.</param> public void InitForDecryption(ECDHPrivateKeyParameters privateKey, ECDHPublicKeyParameters publicKey) { _fingerPrint = (byte[])privateKey.FingerPrint.Clone(); _privateKey = privateKey; _publicKey = publicKey; _forEncryption = false; }
private byte[] ProcessSymmetricKeyDataForEcdh(IPgpPrivateKey privKey, IList <IBigInteger> symmetricKeyData) { var encSymKey = symmetricKeyData[1].ToByteArrayUnsigned(); var privateKey = (ECDHPrivateKeyParameters)privKey.Key; var publicKey = privateKey.PublicKeyParameters; var ephemeralKey = ECDHPublicKeyParameters.Create(symmetricKeyData[0], publicKey.PublicKeyParamSet, publicKey.HashAlgorithm, publicKey.SymmetricKeyAlgorithm); var engine = new RFC6637ECDHEngine(); engine.InitForDecryption(privateKey, ephemeralKey); return(engine.ProcessBlock(encSymKey, 0, encSymKey.Length)); }
public void InitForEncryption(ISecureRandom random, ECDHPublicKeyParameters publicKey, byte[] fingerPrint, out ECDHPublicKeyParameters ephemeralPublicKey) { var genParams = publicKey.CreateKeyGenerationParameters(random, publicKey.HashAlgorithm, publicKey.SymmetricKeyAlgorithm); var generator = new ECKeyPairGenerator("ECDH"); generator.Init(genParams); var ephemeralKeyPair = generator.GenerateKeyPair(); _fingerPrint = (byte[])fingerPrint.Clone(); _privateKey = (ECPrivateKeyParameters)ephemeralKeyPair.Private; _publicKey = publicKey; _forEncryption = true; ephemeralPublicKey = (ECDHPublicKeyParameters)ephemeralKeyPair.Public; }