protected byte[] engineGetEncoded( String format) { if (isASN1FormatString(format)) { return engineGetEncoded(); } return null; }
protected void engineInit( byte[] params, String format) throws IOException { if (isASN1FormatString(format)) { engineInit(params); } else { throw new IOException("Unknown parameter format " + format); } }
protected AlgorithmParameterSpec engineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == null) { throw new NullPointerException("argument to getParameterSpec must not be null"); } return localEngineGetParameterSpec(paramSpec); }
protected Key engineTranslateKey( Key key) throws InvalidKeyException { if (key instanceof DHPublicKey) { return new BCDHPublicKey((DHPublicKey)key); } else if (key instanceof DHPrivateKey) { return new BCDHPrivateKey((DHPrivateKey)key); } throw new InvalidKeyException("key type unknown"); }
protected PrivateKey engineGeneratePrivate( KeySpec keySpec) throws InvalidKeySpecException { if (keySpec instanceof DHPrivateKeySpec) { return new BCDHPrivateKey((DHPrivateKeySpec)keySpec); } return super.engineGeneratePrivate(keySpec); }
public void engineInit( int opmode, Key key, SecureRandom random) throws InvalidKeyException { try { engineInit(opmode, key, (AlgorithmParameterSpec)null, random); } catch (InvalidAlgorithmParameterException e) { throw new IllegalArgumentException("cannot handle supplied parameter spec: " + e.getMessage()); } }
static String publicKeyToString(String algorithm, BigInteger y, DHParameters dhParams) { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); buf.append(algorithm); buf.append(" Public Key [").append(generateKeyFingerprint(y, dhParams)).append("]").append(nl); buf.append(" Y: ").append(y.toString(16)).append(nl); return buf.toString(); }
protected SecretKey engineGenerateSecret( String algorithm) throws NoSuchAlgorithmException { if (x == null) { throw new IllegalStateException("Diffie-Hellman not initialised."); } // for JSSE compatibility if (algorithm.equals("TlsPremasterSecret")) { return new SecretKeySpec(trimZeroes(result), algorithm); } return super.engineGenerateSecret(algorithm); }
protected PublicKey engineGeneratePublic( KeySpec keySpec) throws InvalidKeySpecException { if (keySpec instanceof DHPublicKeySpec) { try { return new BCDHPublicKey((DHPublicKeySpec)keySpec); } catch (IllegalArgumentException e) { throw new ExtendedInvalidKeySpecException(e.getMessage(), e); } } return super.engineGeneratePublic(keySpec); }
protected void engineInit( Key key, SecureRandom random) throws InvalidKeyException { if (!(key instanceof DHPrivateKey)) { throw new InvalidKeyException("DHKeyAgreement requires DHPrivateKey"); } DHPrivateKey privKey = (DHPrivateKey)key; this.p = privKey.getParams().getP(); this.g = privKey.getParams().getG(); this.x = privKey.getX(); this.result = bigIntToBytes(x); }
public String toString() { return DHUtil.publicKeyToString("DH", y, new DHParameters(dhSpec.getP(), dhSpec.getG())); }
public String toString() { return DHUtil.privateKeyToString("DH", x, new DHParameters(dhSpec.getP(), dhSpec.getG())); }
public void initialize( AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { if (!(params instanceof DHParameterSpec)) { throw new InvalidAlgorithmParameterException("parameter object not a DHParameterSpec"); } DHParameterSpec dhParams = (DHParameterSpec)params; try { param = convertParams(random, dhParams); } catch (IllegalArgumentException e) { throw new InvalidAlgorithmParameterException(e.getMessage(), e); } engine.init(param); initialised = true; }
public boolean equals( Object o) { if (!(o instanceof DHPrivateKey)) { return false; } DHPrivateKey other = (DHPrivateKey)o; return this.getX().equals(other.getX()) && this.getParams().getG().equals(other.getParams().getG()) && this.getParams().getP().equals(other.getParams().getP()) && this.getParams().getL() == other.getParams().getL(); }
public boolean equals( Object o) { if (!(o instanceof DHPublicKey)) { return false; } DHPublicKey other = (DHPublicKey)o; return this.getY().equals(other.getY()) && this.getParams().getG().equals(other.getParams().getG()) && this.getParams().getP().equals(other.getParams().getP()) && this.getParams().getL() == other.getParams().getL(); }
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm(); if (algOid.equals(PKCSObjectIdentifiers.dhKeyAgreement)) { return new BCDHPrivateKey(keyInfo); } else if (algOid.equals(X9ObjectIdentifiers.dhpublicnumber)) { return new BCDHPrivateKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
public void engineInit( int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { AlgorithmParameterSpec paramSpec = null; if (params != null) { try { paramSpec = params.getParameterSpec(IESParameterSpec.class); } catch (Exception e) { throw new InvalidAlgorithmParameterException("cannot recognise parameters: " + e.toString()); } } engineParam = params; engineInit(opmode, key, paramSpec, random); }
static String privateKeyToString(String algorithm, BigInteger x, DHParameters dhParams) { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); BigInteger y = dhParams.getG().modPow(x, dhParams.getP()); buf.append(algorithm); buf.append(" Private Key [").append(generateKeyFingerprint(y, dhParams)).append("]").append(nl); buf.append(" Y: ").append(y.toString(16)).append(nl); return buf.toString(); }