private static IAsymmetricBlockCipher createCipher(bool forEncryption, IAsymmetricKey key, IParameters<Algorithm> parameters, SecureRandom random) { IAsymmetricBlockCipher engine = new ElGamalEngine(); ICipherParameters lwParams; if (key is AsymmetricDHPublicKey) { AsymmetricDHPublicKey k = (AsymmetricDHPublicKey)key; lwParams = new ElGamalPublicKeyParameters(k.Y, new DHParameters(k.DomainParameters.P, k.DomainParameters.G, k.DomainParameters.Q, k.DomainParameters.L)); } else { AsymmetricDHPrivateKey k = (AsymmetricDHPrivateKey)key; lwParams = new ElGamalPrivateKeyParameters(k.X, new DHParameters(k.DomainParameters.P, k.DomainParameters.G, k.DomainParameters.Q, k.DomainParameters.L)); } if (parameters.Algorithm.Equals(WrapPkcs1v15.Algorithm)) { engine = new Pkcs1Encoding(engine); } else if (parameters.Algorithm.Equals(WrapOaep.Algorithm)) { OaepWrapParameters oeapParams = (OaepWrapParameters)parameters; engine = new OaepEncoding(engine, FipsShs.CreateDigest(oeapParams.DigestAlgorithm), FipsShs.CreateDigest(oeapParams.MgfDigestAlgorithm), oeapParams.GetEncodingParams()); } if (random != null) { lwParams = new ParametersWithRandom(lwParams, random); } engine.Init(forEncryption, lwParams); return engine; }
public KeyGenerationParameters For(OaepWrapParameters oaepUsage) { return(new KeyGenerationParameters(oaepUsage, this)); }