/** Creates a DSA public key. */ public static PublicKey newDSAPublicKey(String y, String p, String q, String g) throws GeneralSecurityException { return SecurityUtils.getKeyFactory("DSA").generatePublic(new DSAPublicKeySpec(new BigInteger(y, 16), new BigInteger(p, 16), new BigInteger(q, 16), new BigInteger(g, 16)) ); }
/** * Creates object from DSAPublicKeySpec. * * @param keySpec - a DSAPublicKeySpec object */ public DSAPublicKeyImpl(DSAPublicKeySpec keySpec) { super("DSA"); SubjectPublicKeyInfo spki; p = keySpec.getP(); q = keySpec.getQ(); g = keySpec.getG(); ThreeIntegerSequence threeInts = new ThreeIntegerSequence(p .toByteArray(), q.toByteArray(), g.toByteArray()); AlgorithmIdentifier ai = new AlgorithmIdentifier(AlgNameMapper .map2OID("DSA"), threeInts.getEncoded()); y = keySpec.getY(); spki = new SubjectPublicKeyInfo(ai, ASN1Integer.getInstance().encode( y.toByteArray())); setEncoding(spki.getEncoded()); params = (DSAParams) (new DSAParameterSpec(p, q, g)); }
BigInteger m = decodeBigInt(); RSAPublicKeySpec spec = new RSAPublicKeySpec(m, e); return KeyFactory.getInstance("RSA").generatePublic(spec); } else if (type.equals("ssh-dss")) { BigInteger p = decodeBigInt(); BigInteger g = decodeBigInt(); BigInteger y = decodeBigInt(); DSAPublicKeySpec spec = new DSAPublicKeySpec(y, p, q, g); return KeyFactory.getInstance("DSA").generatePublic(spec); } else { throw new IllegalArgumentException("unknown type " + type); System.arraycopy(bytes, pos, bigIntBytes, 0, len); pos += len; return new BigInteger(bigIntBytes);
public static KeyPair loadKey(String pemString, String passwd) throws IOException, GeneralSecurityException { Object key = PEMDecoder.decode(pemString.toCharArray(), passwd); if (key instanceof com.trilead.ssh2.signature.RSAPrivateKey) { com.trilead.ssh2.signature.RSAPrivateKey x = (com.trilead.ssh2.signature.RSAPrivateKey)key; return x.toJCEKeyPair(); } if (key instanceof com.trilead.ssh2.signature.DSAPrivateKey) { com.trilead.ssh2.signature.DSAPrivateKey x = (com.trilead.ssh2.signature.DSAPrivateKey)key; KeyFactory kf = KeyFactory.getInstance("DSA"); return new KeyPair( kf.generatePublic(new DSAPublicKeySpec(x.getY(), x.getP(), x.getQ(), x.getG())), kf.generatePrivate(new DSAPrivateKeySpec(x.getX(), x.getP(), x.getQ(), x.getG()))); } throw new UnsupportedOperationException("Unrecognizable key format: " + key); }
BigInteger q = getMPInt(); BigInteger p = getMPInt(); BigInteger dP = d.remainder(p.subtract(BigInteger.valueOf(1))); BigInteger dQ = d.remainder(q.subtract(BigInteger.valueOf(1))); KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.RSA_ALGORITHM); pub = keyFactory.generatePublic(new RSAPublicKeySpec(n, e)); prv = keyFactory.generatePrivate(new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv)); } else if (KeyPairProvider.SSH_DSS.equals(keyAlg)) { BigInteger p = getMPInt(); BigInteger x = getMPInt(); KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.DSS_ALGORITHM); pub = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g)); prv = keyFactory.generatePrivate(new DSAPrivateKeySpec(x, p, q, g)); } else if (KeyPairProvider.SSH_ED25519.equals(keyAlg)) { return SecurityUtils.extractEDDSAKeyPair(this, keyAlg);
public static DSAPublicKey recoverDSAPublicKey(DSAPrivateKey privateKey) throws GeneralSecurityException { DSAParams keyParams = privateKey.getParams(); BigInteger p = keyParams.getP(); BigInteger x = privateKey.getX(); BigInteger q = keyParams.getQ(); BigInteger g = keyParams.getG(); BigInteger y = g.modPow(x, p); KeyFactory kf = SecurityUtils.getKeyFactory(DSS_ALGORITHM); return (DSAPublicKey) kf.generatePublic(new DSAPublicKeySpec(y, p, q, g)); }
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); }
p = params.getP(); q = params.getQ(); g = params.getG(); return (T) (new DSAPrivateKeySpec(x, p, q, g)); y = publicKey.getY(); DSAParams params = publicKey.getParams(); p = params.getP(); g = params.getG(); return (T) (new DSAPublicKeySpec(y, p, q, g));
if (dsaPubKey.getParams() != null) if (prevDSAPubKey.getParams() == null) DSAParams dsaParams = prevDSAPubKey.getParams(); DSAPublicKeySpec dsaPubKeySpec = new DSAPublicKeySpec( dsaPubKey.getY(), dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()); try KeyFactory keyFactory = KeyFactory.getInstance("DSA", BouncyCastleProvider.PROVIDER_NAME); return keyFactory.generatePublic(dsaPubKeySpec);
public static DSAKeyValue getDSAKeyValue( Document doc, X509Certificate cert) throws XWSSecurityException { try { KeyFactory keyFactory = KeyFactory.getInstance("DSA"); DSAPublicKeySpec dsaPkSpec = (DSAPublicKeySpec) keyFactory.getKeySpec( cert.getPublicKey(), DSAPublicKeySpec.class); return new DSAKeyValue( doc, dsaPkSpec.getP(), dsaPkSpec.getQ(), dsaPkSpec.getG(), dsaPkSpec.getY()); } catch (Exception e) { logger.log(Level.SEVERE,"WSS0426.failed.DSAKeyValue", e); throw new XWSSecurityException(e); } }
@Override public PublicKey readPubKeyFromBuffer(Buffer<?> buf) throws GeneralSecurityException { BigInteger p, q, g, y; try { p = buf.readMPInt(); q = buf.readMPInt(); g = buf.readMPInt(); y = buf.readMPInt(); } catch (Buffer.BufferException be) { throw new GeneralSecurityException(be); } final KeyFactory keyFactory = SecurityUtils.getKeyFactory("DSA"); return keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g)); }
/** * Builds a DSA key from an {@link DSAKeyValue} element and the supplied Java {@link DSAParams}, * which supplies key material from a shared key family. * * @param keyDescriptor the {@link DSAKeyValue} key descriptor * @param dsaParams the {@link DSAParams} DSA key family parameters * * @return a new {@link DSAPublicKey} instance of {@link PublicKey} * * @throws KeyException thrown if the key algorithm is not supported by the JCE or the key spec does not * contain valid information */ public static PublicKey getDSAKey(DSAKeyValue keyDescriptor, DSAParams dsaParams) throws KeyException { BigInteger yComponent = keyDescriptor.getY().getValueBigInt(); DSAPublicKeySpec keySpec = new DSAPublicKeySpec(yComponent, dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()); return buildKey(keySpec, "DSA"); }
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); }
factory = KeyFactory.getInstance("RSA"); } catch (NoSuchAlgorithmException s) { throw new IOException(s.getMessage(), s); factory.generatePublic(new RSAPublicKeySpec(n, e)), factory.generatePrivate(new RSAPrivateKeySpec(n, d)) ); } catch (InvalidKeySpecException i) { factory.generatePublic(new DSAPublicKeySpec(y, p, q, g)), factory.generatePrivate(new DSAPrivateKeySpec(x, p, q, g)) ); } catch (InvalidKeySpecException e) {
BigInteger q = getMPInt(); BigInteger p = getMPInt(); BigInteger dP = d.remainder(p.subtract(BigInteger.valueOf(1))); BigInteger dQ = d.remainder(q.subtract(BigInteger.valueOf(1))); KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.RSA_ALGORITHM); pub = keyFactory.generatePublic(new RSAPublicKeySpec(n, e)); prv = keyFactory.generatePrivate(new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv)); } else if (KeyPairProvider.SSH_DSS.equals(keyAlg)) { BigInteger p = getMPInt(); BigInteger x = getMPInt(); KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.DSS_ALGORITHM); pub = keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g)); prv = keyFactory.generatePrivate(new DSAPrivateKeySpec(x, p, q, g)); } else if (KeyPairProvider.SSH_ED25519.equals(keyAlg)) { return SecurityUtils.extractEDDSAKeyPair(this, keyAlg);
public static DSAPublicKey recoverDSAPublicKey(DSAPrivateKey privateKey) throws GeneralSecurityException { DSAParams keyParams = privateKey.getParams(); BigInteger p = keyParams.getP(); BigInteger x = privateKey.getX(); BigInteger q = keyParams.getQ(); BigInteger g = keyParams.getG(); BigInteger y = g.modPow(x, p); KeyFactory kf = SecurityUtils.getKeyFactory(DSS_ALGORITHM); return (DSAPublicKey) kf.generatePublic(new DSAPublicKeySpec(y, p, q, g)); }
protected static PublicKey createPubKeyDsa( BigInteger y, BigInteger p, BigInteger q, BigInteger g) throws NoSuchAlgorithmException, InvalidKeySpecException { DSAPublicKeySpec keySpec = new DSAPublicKeySpec(y, p, q, g); KeyFactory kf = KeyFactory.getInstance("DSA"); return kf.generatePublic(keySpec); }
return engineGeneratePrivate(new DSAPrivateKeySpec( privateKey.getX(), params.getP(), params.getQ(), params.getG())); } catch (InvalidKeySpecException e) { DSAParams params = publicKey.getParams(); return engineGeneratePublic(new DSAPublicKeySpec(publicKey .getY(), params.getP(), params.getQ(), params .getG())); } catch (InvalidKeySpecException e) {
if (dsaPubKey.getParams() != null) if (prevDSAPubKey.getParams() == null) DSAParams dsaParams = prevDSAPubKey.getParams(); DSAPublicKeySpec dsaPubKeySpec = new DSAPublicKeySpec( dsaPubKey.getY(), dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()); try KeyFactory keyFactory = KeyFactory.getInstance("DSA", BouncyCastleProvider.PROVIDER_NAME); return keyFactory.generatePublic(dsaPubKeySpec);
@Override public PublicKey readPubKeyFromBuffer(String type, Buffer<?> buf) throws GeneralSecurityException { BigInteger p, q, g, y; try { p = buf.readMPInt(); q = buf.readMPInt(); g = buf.readMPInt(); y = buf.readMPInt(); } catch (Buffer.BufferException be) { throw new GeneralSecurityException(be); } final KeyFactory keyFactory = SecurityUtils.getKeyFactory("DSA"); return keyFactory.generatePublic(new DSAPublicKeySpec(y, p, q, g)); }