protected byte[] engineGetEncoded( String format) { if (isASN1FormatString(format)) { return engineGetEncoded(); } return null; }
protected void engineInitSign( PrivateKey privateKey, SecureRandom random) throws InvalidKeyException { this.random = random; engineInitSign(privateKey); }
/** * Generates a DSA key pair. * * @param random Random source required for key generation. * @param bitLength Desired key size in bits. * * @return DSA key pair of desired size. */ public static KeyPair generateDSA(final SecureRandom random, final int bitLength) { final org.bouncycastle.jcajce.provider.asymmetric.dsa.KeyPairGeneratorSpi generator = new org.bouncycastle.jcajce.provider.asymmetric.dsa.KeyPairGeneratorSpi(); generator.initialize(bitLength, random); return generator.generateKeyPair(); }
public String toString() { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); buf.append("DSA Public Key [").append(DSAUtil.generateKeyFingerprint(y, getParams())).append("]").append(nl); buf.append(" Y: ").append(this.getY().toString(16)).append(nl); return buf.toString(); }
public PublicKey generatePublic(SubjectPublicKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getAlgorithm().getAlgorithm(); if (DSAUtil.isDsaOid(algOid)) { return new BCDSAPublicKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm(); if (DSAUtil.isDsaOid(algOid)) { return new BCDSAPrivateKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
protected Key engineTranslateKey( Key key) throws InvalidKeyException { if (key instanceof DSAPublicKey) { return new BCDSAPublicKey((DSAPublicKey)key); } else if (key instanceof DSAPrivateKey) { return new BCDSAPrivateKey((DSAPrivateKey)key); } throw new InvalidKeyException("key type unknown"); }
protected void engineInit( byte[] params, String format) throws IOException { if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509")) { engineInit(params); } else { throw new IOException("Unknown parameter format " + format); } }
public String toString() { StringBuffer buf = new StringBuffer(); String nl = Strings.lineSeparator(); BigInteger y = getParams().getG().modPow(x, getParams().getP()); buf.append("DSA Private Key [").append(DSAUtil.generateKeyFingerprint(y, getParams())).append("]").append(nl); buf.append(" Y: ").append(y.toString(16)).append(nl); return buf.toString(); } }
protected void engineInitVerify( PublicKey publicKey) throws InvalidKeyException { CipherParameters param = DSAUtil.generatePublicKeyParameter(publicKey); digest.reset(); signer.init(false, param); }
private void readObject( ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); BigInteger p = (BigInteger)in.readObject(); if (p.equals(ZERO)) { this.dsaSpec = null; } else { this.dsaSpec = new DSAParameterSpec(p, (BigInteger)in.readObject(), (BigInteger)in.readObject()); } this.lwKeyParams = new DSAPublicKeyParameters(y, DSAUtil.toDSAParameters(dsaSpec)); }
protected void engineInitSign( PrivateKey privateKey) throws InvalidKeyException { CipherParameters param = DSAUtil.generatePrivateKeyParameter(privateKey); if (random != null) { param = new ParametersWithRandom(param, random); } digest.reset(); signer.init(true, param); }
protected AlgorithmParameterSpec engineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == null) { throw new NullPointerException("argument to getParameterSpec must not be null"); } return localEngineGetParameterSpec(paramSpec); }
/** * Return a PKCS8 representation of the key. The sequence returned * represents a full PrivateKeyInfo object. * * @return a PKCS8 representation of the key. */ public byte[] getEncoded() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG()).toASN1Primitive()), new ASN1Integer(getX())); }
public boolean equals( Object o) { if (!(o instanceof DSAPrivateKey)) { return false; } DSAPrivateKey other = (DSAPrivateKey)o; return this.getX().equals(other.getX()) && this.getParams().getG().equals(other.getParams().getG()) && this.getParams().getP().equals(other.getParams().getP()) && this.getParams().getQ().equals(other.getParams().getQ()); }
public boolean equals( Object o) { if (!(o instanceof DSAPublicKey)) { return false; } DSAPublicKey other = (DSAPublicKey)o; if (this.dsaSpec != null) { return this.getY().equals(other.getY()) && other.getParams() != null && this.getParams().getG().equals(other.getParams().getG()) && this.getParams().getP().equals(other.getParams().getP()) && this.getParams().getQ().equals(other.getParams().getQ()); } else { return this.getY().equals(other.getY()) && other.getParams() == null; } }
BCDSAPublicKey( DSAPublicKey key) { this.y = key.getY(); this.dsaSpec = key.getParams(); this.lwKeyParams = new DSAPublicKeyParameters(y, DSAUtil.toDSAParameters(dsaSpec)); }
BCDSAPublicKey( DSAPublicKeySpec spec) { this.y = spec.getY(); this.dsaSpec = new DSAParameterSpec(spec.getP(), spec.getQ(), spec.getG()); this.lwKeyParams = new DSAPublicKeyParameters(y, DSAUtil.toDSAParameters(dsaSpec)); }