static public AsymmetricKeyParameter generatePublicKeyParameter( PublicKey key) throws InvalidKeyException { if (key instanceof BCDSAPublicKey) { return ((BCDSAPublicKey)key).engineGetKeyParameters(); } if (key instanceof DSAPublicKey) { return new BCDSAPublicKey((DSAPublicKey)key).engineGetKeyParameters(); } try { byte[] bytes = key.getEncoded(); BCDSAPublicKey bckey = new BCDSAPublicKey(SubjectPublicKeyInfo.getInstance(bytes)); return bckey.engineGetKeyParameters(); } catch (Exception e) { throw new InvalidKeyException("can't identify DSA public key: " + key.getClass().getName()); } }
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"); }
public BCDSAPublicKey( SubjectPublicKeyInfo info) { ASN1Integer derY; try { derY = (ASN1Integer)info.parsePublicKey(); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in DSA public key"); } this.y = derY.getValue(); if (isNotNull(info.getAlgorithm().getParameters())) { DSAParameter params = DSAParameter.getInstance(info.getAlgorithm().getParameters()); this.dsaSpec = new DSAParameterSpec(params.getP(), params.getQ(), params.getG()); } else { this.dsaSpec = null; } this.lwKeyParams = new DSAPublicKeyParameters(y, DSAUtil.toDSAParameters(dsaSpec)); }
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 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(); }
DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)pair.getPrivate(); return new KeyPair(new BCDSAPublicKey(pub), new BCDSAPrivateKey(priv));
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; } }
return new BCDSAPublicKey((DSAPublicKeySpec)keySpec);