use of java.security.spec.DSAPublicKeySpec in project Pix-Art-Messenger by kriztan.
the class OtrService method saveKey.
private void saveKey() {
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
KeyFactory keyFactory;
try {
keyFactory = KeyFactory.getInstance("DSA");
DSAPrivateKeySpec privateKeySpec = keyFactory.getKeySpec(privateKey, DSAPrivateKeySpec.class);
DSAPublicKeySpec publicKeySpec = keyFactory.getKeySpec(publicKey, DSAPublicKeySpec.class);
this.account.setKey("otr_x", privateKeySpec.getX().toString(16));
this.account.setKey("otr_g", privateKeySpec.getG().toString(16));
this.account.setKey("otr_p", privateKeySpec.getP().toString(16));
this.account.setKey("otr_q", privateKeySpec.getQ().toString(16));
this.account.setKey("otr_y", publicKeySpec.getY().toString(16));
} catch (final NoSuchAlgorithmException | InvalidKeySpecException e) {
e.printStackTrace();
}
}
use of java.security.spec.DSAPublicKeySpec in project santuario-java by apache.
the class DsaKeyValueSecurityToken method buildPublicKey.
private PublicKey buildPublicKey(DSAKeyValueType dsaKeyValueType) throws InvalidKeySpecException, NoSuchAlgorithmException {
DSAPublicKeySpec dsaPublicKeySpec = new DSAPublicKeySpec(new BigInteger(1, dsaKeyValueType.getY()), new BigInteger(1, dsaKeyValueType.getP()), new BigInteger(1, dsaKeyValueType.getQ()), new BigInteger(1, dsaKeyValueType.getG()));
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
return keyFactory.generatePublic(dsaPublicKeySpec);
}
use of java.security.spec.DSAPublicKeySpec in project i2p.i2p by i2p.
the class SigUtil method toJavaDSAKey.
public static DSAPublicKey toJavaDSAKey(SigningPublicKey pk) throws GeneralSecurityException {
KeyFactory kf = KeyFactory.getInstance("DSA");
// y p q g
KeySpec ks = new DSAPublicKeySpec(new NativeBigInteger(1, pk.getData()), CryptoConstants.dsap, CryptoConstants.dsaq, CryptoConstants.dsag);
return (DSAPublicKey) kf.generatePublic(ks);
}
use of java.security.spec.DSAPublicKeySpec in project cloudbreak by hortonworks.
the class PublicKeyReaderUtil method decodeDSAPublicKey.
private static PublicKey decodeDSAPublicKey(SSH2DataBuffer buffer) throws PublicKeyParseException {
BigInteger p = buffer.readMPint();
BigInteger q = buffer.readMPint();
BigInteger g = buffer.readMPint();
BigInteger y = buffer.readMPint();
try {
KeyFactory dsaKeyFact = KeyFactory.getInstance("DSA");
KeySpec dsaPubSpec = new DSAPublicKeySpec(y, p, q, g);
return dsaKeyFact.generatePublic(dsaPubSpec);
} catch (Exception e) {
throw new PublicKeyParseException(ErrorCode.SSH2DSA_ERROR_DECODING_PUBLIC_KEY_BLOB, e);
}
}
use of java.security.spec.DSAPublicKeySpec in project jruby-openssl by jruby.
the class PKeyDSA method setKeySpecComponent.
private IRubyObject setKeySpecComponent(final int index, final IRubyObject value) {
final BigInteger val = BN.getBigInteger(value);
switch(index) {
case SPEC_X:
this.dsa_x = val;
break;
case SPEC_Y:
this.dsa_y = val;
break;
case SPEC_P:
this.dsa_p = val;
break;
case SPEC_Q:
this.dsa_q = val;
break;
case SPEC_G:
this.dsa_g = val;
break;
}
// Don't access the dsa_p, dsa_q and dsa_g fields directly. They may
// have already been consumed and cleared.
BigInteger _dsa_p = getP();
BigInteger _dsa_q = getQ();
BigInteger _dsa_g = getG();
if (dsa_x != null && _dsa_p != null && _dsa_q != null && _dsa_g != null) {
// we now have all private key components. create the key :
DSAPrivateKeySpec spec = new DSAPrivateKeySpec(dsa_x, _dsa_p, _dsa_q, _dsa_g);
try {
this.privateKey = (DSAPrivateKey) SecurityHelper.getKeyFactory("DSA").generatePrivate(spec);
} catch (InvalidKeySpecException e) {
throw newDSAError(getRuntime(), "invalid keyspec", e);
} catch (NoSuchAlgorithmException e) {
throw newDSAError(getRuntime(), "unsupported key algorithm (DSA)", e);
}
// clear out the specValues
this.dsa_x = this.dsa_p = this.dsa_q = this.dsa_g = null;
}
if (dsa_y != null && _dsa_p != null && _dsa_q != null && _dsa_g != null) {
// we now have all public key components. create the key :
DSAPublicKeySpec spec = new DSAPublicKeySpec(dsa_y, _dsa_p, _dsa_q, _dsa_g);
try {
this.publicKey = (DSAPublicKey) SecurityHelper.getKeyFactory("DSA").generatePublic(spec);
} catch (InvalidKeySpecException e) {
throw newDSAError(getRuntime(), "invalid keyspec", e);
} catch (NoSuchAlgorithmException e) {
throw newDSAError(getRuntime(), "unsupported key algorithm (DSA)", e);
}
// clear out the specValues
this.dsa_y = this.dsa_p = this.dsa_q = this.dsa_g = null;
}
return value;
}
Aggregations