GMSEncrypt(Services services, String dhSKAlgo) throws Exception { this.services = services; this.dhSKAlgo = dhSKAlgo; // Initialize the keys when either the host is a peer that has // non-blank setting for DH symmetric algo, or this is a server // that has authenticator defined. if ((this.dhSKAlgo != null && this.dhSKAlgo.length() > 0)) { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH"); DHParameterSpec dhSpec = new DHParameterSpec(dhP, dhG, dhL); keyGen.initialize(dhSpec); KeyPair keypair = keyGen.generateKeyPair(); // Get the generated public and private keys dhPrivateKey = keypair.getPrivate(); dhPublicKey = keypair.getPublic(); } else { dhPrivateKey = null; dhPublicKey = null; } }
/** * Initialize the Diffie-Hellman keys. This method is not thread safe */ public static void initDHKeys(DistributionConfig config) throws Exception { dhSKAlgo = config.getSecurityClientDHAlgo(); dhPrivateKey = null; dhPublicKey = null; // Initialize the keys when either the host is a client that has // non-blank setting for DH symmetric algo, or this is a server // that has authenticator defined. if ((dhSKAlgo != null && dhSKAlgo.length() > 0) /* || securityService.isClientSecurityRequired() */) { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH"); DHParameterSpec dhSpec = new DHParameterSpec(dhP, dhG, dhL); keyGen.initialize(dhSpec); KeyPair keypair = keyGen.generateKeyPair(); // Get the generated public and private keys dhPrivateKey = keypair.getPrivate(); dhPublicKey = keypair.getPublic(); random = new SecureRandom(); // Force the random generator to seed itself. byte[] someBytes = new byte[48]; random.nextBytes(someBytes); } }
@Override protected void initDH(DHBase dh) throws GeneralSecurityException { dh.init(new DHParameterSpec(DHGroupData.P14, DHGroupData.G), trans.getConfig().getRandomFactory()); } }
@Override protected void initDH(DHBase dh) throws GeneralSecurityException { dh.init(new DHParameterSpec(group, generator), trans.getConfig().getRandomFactory()); } }
@Override protected void initDH(DHBase dh) throws GeneralSecurityException { dh.init(new DHParameterSpec(DHGroupData.P1, DHGroupData.G), trans.getConfig().getRandomFactory()); } }
private boolean parseGexGroup(SSHPacket buffer) throws Buffer.BufferException, GeneralSecurityException, TransportException { BigInteger p = buffer.readMPInt(); BigInteger g = buffer.readMPInt(); int bitLength = p.bitLength(); if (bitLength < minBits || bitLength > maxBits) { throw new GeneralSecurityException("Server generated gex p is out of range (" + bitLength + " bits)"); } log.debug("Received server p bitlength {}", bitLength); dh.init(new DHParameterSpec(p, g), trans.getConfig().getRandomFactory()); log.debug("Sending {}", Message.KEX_DH_GEX_INIT); trans.write(new SSHPacket(Message.KEX_DH_GEX_INIT).putBytes(dh.getE())); return false; } }
public DHParameterSpec getParams() { return new DHParameterSpec(elSpec.getP(), elSpec.getG()); }
public DHParameterSpec getParams() { return new DHParameterSpec(elSpec.getP(), elSpec.getG()); }
private void readObject( ObjectInputStream in) throws IOException, ClassNotFoundException { x = (BigInteger)in.readObject(); this.dhSpec = new DHParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), in.readInt()); }
private void readObject( ObjectInputStream in) throws IOException, ClassNotFoundException { this.y = (BigInteger)in.readObject(); this.dhSpec = new DHParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), in.readInt()); }
private void readObject( ObjectInputStream in) throws IOException, ClassNotFoundException { this.y = (BigInteger)in.readObject(); this.dhSpec = new DHParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), in.readInt()); }
private void readObject( ObjectInputStream in) throws IOException, ClassNotFoundException { x = (BigInteger)in.readObject(); this.dhSpec = new DHParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), in.readInt()); }
private void readObject( ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); this.dhSpec = new DHParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), in.readInt()); this.info = null; this.attrCarrier = new PKCS12BagAttributeCarrierImpl(); }
@Override public byte[] getE() throws Exception { if (e == null) { DHParameterSpec dhSkipParamSpec = new DHParameterSpec(p, g); myKpairGen.initialize(dhSkipParamSpec); KeyPair myKpair = myKpairGen.generateKeyPair(); myKeyAgree.init(myKpair.getPrivate()); e = ((javax.crypto.interfaces.DHPublicKey) (myKpair.getPublic())).getY(); e_array = e.toByteArray(); } return e_array; }
public void init(BigInteger p, BigInteger g) throws GeneralSecurityException { this.p = p; this.g = g; generator.initialize(new DHParameterSpec(p, g)); final KeyPair kp = generator.generateKeyPair(); agreement.init(kp.getPrivate()); e = ((javax.crypto.interfaces.DHPublicKey) kp.getPublic()).getY(); }
JCEDHPrivateKey( DHPrivateKeySpec spec) { this.x = spec.getX(); this.dhSpec = new DHParameterSpec(spec.getP(), spec.getG()); }
JCEDHPublicKey( DHPublicKeySpec spec) { this.y = spec.getY(); this.dhSpec = new DHParameterSpec(spec.getP(), spec.getG()); }
BCDHPrivateKey( DHPrivateKeySpec spec) { this.x = spec.getX(); this.dhSpec = new DHParameterSpec(spec.getP(), spec.getG()); }
BCDHPublicKey( DHPublicKeyParameters params) { this.y = params.getY(); this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL()); }
JCEDHPrivateKey( DHPrivateKeyParameters params) { this.x = params.getX(); this.dhSpec = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL()); }