Search in sources :

Example 51 with DSAPublicKeySpec

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();
    }
}
Also used : DSAPrivateKeySpec(java.security.spec.DSAPrivateKeySpec) PrivateKey(java.security.PrivateKey) PublicKey(java.security.PublicKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyFactory(java.security.KeyFactory) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Example 52 with DSAPublicKeySpec

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);
}
Also used : BigInteger(java.math.BigInteger) KeyFactory(java.security.KeyFactory) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Example 53 with 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);
}
Also used : NativeBigInteger(net.i2p.util.NativeBigInteger) ECPublicKeySpec(java.security.spec.ECPublicKeySpec) EdDSAPublicKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec) ECPrivateKeySpec(java.security.spec.ECPrivateKeySpec) KeySpec(java.security.spec.KeySpec) DSAPrivateKeySpec(java.security.spec.DSAPrivateKeySpec) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) EdDSAPrivateKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec) RSAPrivateKeySpec(java.security.spec.RSAPrivateKeySpec) KeyFactory(java.security.KeyFactory) EdDSAPublicKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec) DSAPublicKey(java.security.interfaces.DSAPublicKey) EdDSAPublicKey(net.i2p.crypto.eddsa.EdDSAPublicKey)

Example 54 with DSAPublicKeySpec

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);
    }
}
Also used : DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec) KeySpec(java.security.spec.KeySpec) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) BigInteger(java.math.BigInteger) KeyFactory(java.security.KeyFactory) NoSuchElementException(java.util.NoSuchElementException) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Example 55 with DSAPublicKeySpec

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;
}
Also used : DSAPrivateKeySpec(java.security.spec.DSAPrivateKeySpec) BigInteger(java.math.BigInteger) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Aggregations

DSAPublicKeySpec (java.security.spec.DSAPublicKeySpec)63 BigInteger (java.math.BigInteger)45 KeyFactory (java.security.KeyFactory)37 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)23 PublicKey (java.security.PublicKey)22 DSAPublicKey (java.security.interfaces.DSAPublicKey)21 DSAPrivateKeySpec (java.security.spec.DSAPrivateKeySpec)19 KeySpec (java.security.spec.KeySpec)19 DSAParams (java.security.interfaces.DSAParams)17 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)17 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 PrivateKey (java.security.PrivateKey)10 GeneralSecurityException (java.security.GeneralSecurityException)9 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)9 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)9 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)9 IOException (java.io.IOException)7 CertPathValidatorException (java.security.cert.CertPathValidatorException)7 InvalidKeyException (java.security.InvalidKeyException)5 KeyPair (java.security.KeyPair)5