public void init( CipherParameters param) { AsymmetricKeyParameter kParam; if (typeof(ParametersWithRandom).IsInstanceOfType(param)) { ParametersWithRandom rParam = (ParametersWithRandom)param; this.random = rParam.getRandom(); kParam = (AsymmetricKeyParameter)rParam.getParameters(); } else { this.random = new SecureRandom(); kParam = (AsymmetricKeyParameter)param; } if (!(typeof(DHPrivateKeyParameters).IsInstanceOfType(kParam))) { throw new ArgumentException("DHEngine expects DHPrivateKeyParameters"); } this.key = (DHPrivateKeyParameters)kParam; this.dhParams = key.getParameters(); }
public static PrivateKeyInfo createPrivateKeyInfo(AsymmetricKeyParameter key) { /* * Process DH private key. * The value for L was set to zero implicitly. * This is the same action as found in JCEDHPrivateKey getEncoded method. */ if (key is ElGamalPrivateKeyParameters) { ElGamalPrivateKeyParameters _key = (ElGamalPrivateKeyParameters)key; PrivateKeyInfo info = new PrivateKeyInfo( new AlgorithmIdentifier( OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter( _key.getParameters().getP(), _key.getParameters().getG()).toASN1Object()), new DERInteger(_key.getX())); return(info); } if (key is DSAPrivateKeyParameters) { DSAPrivateKeyParameters _key = (DSAPrivateKeyParameters)key; PrivateKeyInfo info = new PrivateKeyInfo( new AlgorithmIdentifier( X9ObjectIdentifiers.id_dsa, new DSAParameter( _key.getParameters().getP(), _key.getParameters().getQ(), _key.getParameters().getG()).toASN1Object()), new DERInteger(_key.getX())); return(info); } if (key is DHPrivateKeyParameters) { DHPrivateKeyParameters _key = (DHPrivateKeyParameters)key; PrivateKeyInfo info = new PrivateKeyInfo( new AlgorithmIdentifier( PKCSObjectIdentifiers.dhKeyAgreement, new DHParameter( _key.getParameters().getP(), _key.getParameters().getG(), 0 ).toASN1Object() ) , new DERInteger(_key.getX())); return(info); } if (key is RSAPrivateCrtKeyParameters) { RSAPrivateCrtKeyParameters _key = (RSAPrivateCrtKeyParameters)key; PrivateKeyInfo info = new PrivateKeyInfo( new AlgorithmIdentifier( PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new RSAPrivateKeyStructure( _key.getModulus(), _key.getPublicExponent(), _key.getExponent(), _key.getP(), _key.getQ(), _key.getDP(), _key.getDQ(), _key.getQInv()).toASN1Object()); return(info); } if (key is ECPrivateKeyParameters) { ECPrivateKeyParameters _key = (ECPrivateKeyParameters)key; X9ECParameters ecP = new X9ECParameters( _key.getParameters().getCurve(), _key.getParameters().getG(), _key.getParameters().getN(), _key.getParameters().getH(), _key.getParameters().getSeed()); X962Parameters x962 = new X962Parameters(ecP); PrivateKeyInfo info = new PrivateKeyInfo( new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, x962.toASN1Object()), new ECPrivateKeyStructure(_key.getD()).toASN1Object()); return(info); } throw (new Exception("Class provided is not convertable:" + key.GetType())); }