Java Code Examples for java.security.interfaces.DSAPublicKey#getParams()

The following examples show how to use java.security.interfaces.DSAPublicKey#getParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DOMKeyValue.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 2
Source File: DOMKeyValue.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 3
Source File: DOMKeyValue.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 4
Source File: DOMKeyValue.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 5
Source File: DOMKeyValue.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 6
Source File: DOMKeyValue.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 7
Source File: DOMKeyValue.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 8
Source File: DOMKeyValue.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 9
Source File: DOMKeyValue.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 10
Source File: DOMKeyValue.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 11
Source File: DOMKeyValue.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
DSA(PublicKey key) throws KeyException {
    super(key);
    DSAPublicKey dkey = (DSAPublicKey) key;
    DSAParams params = dkey.getParams();
    p = new DOMCryptoBinary(params.getP());
    q = new DOMCryptoBinary(params.getQ());
    g = new DOMCryptoBinary(params.getG());
    y = new DOMCryptoBinary(dkey.getY());
}
 
Example 12
Source File: FingerprintGenerator.java    From httpsig-java with The Unlicense 5 votes vote down vote up
public String getFingerprint(PublicKey publicKey) {
    ByteArrayOutputStream byteOs = new ByteArrayOutputStream();
    try {
        if (publicKey instanceof DSAPublicKey) {
            DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey;
            DSAParams dsaParams = dsaPublicKey.getParams();

            DataOutputStream dos = new DataOutputStream(byteOs);
            dos.writeInt(KeyFormat.SSH_DSS.getIdentifier().getBytes().length);
            dos.write(KeyFormat.SSH_DSS.getIdentifier().getBytes());
            dos.writeInt(dsaParams.getP().toByteArray().length);
            dos.write(dsaParams.getP().toByteArray());
            dos.writeInt(dsaParams.getQ().toByteArray().length);
            dos.write(dsaParams.getQ().toByteArray());
            dos.writeInt(dsaParams.getG().toByteArray().length);
            dos.write(dsaParams.getG().toByteArray());
            dos.writeInt(dsaPublicKey.getY().toByteArray().length);
            dos.write(dsaPublicKey.getY().toByteArray());
        } else {
            throw new IllegalArgumentException("Not a DSA public key: " + publicKey);
        }
        return Magic.getFingerprint(byteOs.toByteArray());
    } catch (IOException e) {
        LOGGER.error("[getFingerprint] failed to generate DSA fingerprint", e);
    } finally {
        try {
            byteOs.close();
        } catch (IOException ignored) {
        }
    }

    return null;
}
 
Example 13
Source File: JDKDSAPublicKey.java    From ripple-lib-java with ISC License 4 votes vote down vote up
JDKDSAPublicKey(
    DSAPublicKey    key)
{
    this.y = key.getY();
    this.dsaSpec = key.getParams();
}
 
Example 14
Source File: DProperties.java    From keystore-explorer with GNU General Public License v3.0 4 votes vote down vote up
private void createPublicKeyNodes(DefaultMutableTreeNode parentNode, PublicKey publicKey) throws CryptoException {
	DefaultMutableTreeNode publicKeyNode = new DefaultMutableTreeNode(
			res.getString("DProperties.properties.PublicKey"));
	parentNode.add(publicKeyNode);

	KeyInfo keyInfo = KeyPairUtil.getKeyInfo(publicKey);
	String keyAlg = keyInfo.getAlgorithm();

	publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(
			res.getString("DProperties.properties.Algorithm"), keyAlg)));

	Integer keySize = keyInfo.getSize();

	if (keySize != null) {
		publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(
				res.getString("DProperties.properties.KeySize"), "" + keyInfo.getSize())));
	} else {
		publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(
				res.getString("DProperties.properties.KeySize"), "?")));
	}

	String keyFormat = publicKey.getFormat();

	publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(
			res.getString("DProperties.properties.Format"), keyFormat)));

	String keyEncoded = "0x" + new BigInteger(1, publicKey.getEncoded()).toString(16).toUpperCase();

	publicKeyNode.add(new DefaultMutableTreeNode(MessageFormat.format(
			res.getString("DProperties.properties.Encoded"), keyEncoded)));

	if (publicKey instanceof RSAPublicKey) {
		RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;

		String publicExponent = MessageFormat.format(
				res.getString("DProperties.properties.public.rsa.PublicExponent"), "0x"
						+ rsaPublicKey.getPublicExponent().toString(16).toUpperCase());
		publicKeyNode.add(new DefaultMutableTreeNode(publicExponent));

		String modulus = MessageFormat.format(res.getString("DProperties.properties.public.rsa.Modulus"), "0x"
				+ rsaPublicKey.getModulus().toString(16).toUpperCase());
		publicKeyNode.add(new DefaultMutableTreeNode(modulus));

	} else if (publicKey instanceof DSAPublicKey) {
		DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey;

		DSAParams dsaParams = dsaPublicKey.getParams();

		String primeModulusP = MessageFormat.format(
				res.getString("DProperties.properties.public.dsa.PrimeModulusP"),
				"0x" + dsaParams.getP().toString(16).toUpperCase());
		publicKeyNode.add(new DefaultMutableTreeNode(primeModulusP));

		String primeQ = MessageFormat.format(res.getString("DProperties.properties.public.dsa.PrimeQ"), "0x"
				+ dsaParams.getQ().toString(16).toUpperCase());
		publicKeyNode.add(new DefaultMutableTreeNode(primeQ));

		String generatorG = MessageFormat.format(res.getString("DProperties.properties.public.dsa.GeneratorG"),
				"0x" + dsaParams.getG().toString(16).toUpperCase());
		publicKeyNode.add(new DefaultMutableTreeNode(generatorG));

		String publicKeyY = MessageFormat.format(res.getString("DProperties.properties.public.dsa.PublicKeyY"),
				"0x" + dsaPublicKey.getY().toString(16).toUpperCase());
		publicKeyNode.add(new DefaultMutableTreeNode(publicKeyY));
	}
}
 
Example 15
Source File: CertPathValidatorUtilities.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
/**
 * Return the next working key inheriting DSA parameters if necessary.
 * <p>
 * This methods inherits DSA parameters from the indexed certificate or
 * previous certificates in the certificate chain to the returned
 * <code>PublicKey</code>. The list is searched upwards, meaning the end
 * certificate is at position 0 and previous certificates are following.
 * </p>
 * <p>
 * If the indexed certificate does not contain a DSA key this method simply
 * returns the public key. If the DSA key already contains DSA parameters
 * the key is also only returned.
 * </p>
 *
 * @param certs The certification path.
 * @param index The index of the certificate which contains the public key
 *              which should be extended with DSA parameters.
 * @return The public key of the certificate in list position
 *         <code>index</code> extended with DSA parameters if applicable.
 * @throws AnnotatedException if DSA parameters cannot be inherited.
 */
protected static PublicKey getNextWorkingKey(List certs, int index)
    throws CertPathValidatorException
{
    Certificate cert = (Certificate)certs.get(index);
    PublicKey pubKey = cert.getPublicKey();
    if (!(pubKey instanceof DSAPublicKey))
    {
        return pubKey;
    }
    DSAPublicKey dsaPubKey = (DSAPublicKey)pubKey;
    if (dsaPubKey.getParams() != null)
    {
        return dsaPubKey;
    }
    for (int i = index + 1; i < certs.size(); i++)
    {
        X509Certificate parentCert = (X509Certificate)certs.get(i);
        pubKey = parentCert.getPublicKey();
        if (!(pubKey instanceof DSAPublicKey))
        {
            throw new CertPathValidatorException(
                "DSA parameters cannot be inherited from previous certificate.");
        }
        DSAPublicKey prevDSAPubKey = (DSAPublicKey)pubKey;
        if (prevDSAPubKey.getParams() == null)
        {
            continue;
        }
        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);
        }
        catch (Exception exception)
        {
            throw new RuntimeException(exception.getMessage());
        }
    }
    throw new CertPathValidatorException("DSA parameters cannot be inherited from previous certificate.");
}
 
Example 16
Source File: CertPathValidatorUtilities.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
/**
 * Return the next working key inheriting DSA parameters if necessary.
 * <p>
 * This methods inherits DSA parameters from the indexed certificate or
 * previous certificates in the certificate chain to the returned
 * <code>PublicKey</code>. The list is searched upwards, meaning the end
 * certificate is at position 0 and previous certificates are following.
 * </p>
 * <p>
 * If the indexed certificate does not contain a DSA key this method simply
 * returns the public key. If the DSA key already contains DSA parameters
 * the key is also only returned.
 * </p>
 *
 * @param certs The certification path.
 * @param index The index of the certificate which contains the public key
 *              which should be extended with DSA parameters.
 * @return The public key of the certificate in list position
 *         <code>index</code> extended with DSA parameters if applicable.
 * @throws AnnotatedException if DSA parameters cannot be inherited.
 */
protected static PublicKey getNextWorkingKey(List certs, int index, JcaJceHelper helper)
    throws CertPathValidatorException
{
    Certificate cert = (Certificate)certs.get(index);
    PublicKey pubKey = cert.getPublicKey();
    if (!(pubKey instanceof DSAPublicKey))
    {
        return pubKey;
    }
    DSAPublicKey dsaPubKey = (DSAPublicKey)pubKey;
    if (dsaPubKey.getParams() != null)
    {
        return dsaPubKey;
    }
    for (int i = index + 1; i < certs.size(); i++)
    {
        X509Certificate parentCert = (X509Certificate)certs.get(i);
        pubKey = parentCert.getPublicKey();
        if (!(pubKey instanceof DSAPublicKey))
        {
            throw new CertPathValidatorException(
                "DSA parameters cannot be inherited from previous certificate.");
        }
        DSAPublicKey prevDSAPubKey = (DSAPublicKey)pubKey;
        if (prevDSAPubKey.getParams() == null)
        {
            continue;
        }
        DSAParams dsaParams = prevDSAPubKey.getParams();
        DSAPublicKeySpec dsaPubKeySpec = new DSAPublicKeySpec(
            dsaPubKey.getY(), dsaParams.getP(), dsaParams.getQ(), dsaParams.getG());
        try
        {
            KeyFactory keyFactory = helper.createKeyFactory("DSA");
            return keyFactory.generatePublic(dsaPubKeySpec);
        }
        catch (Exception exception)
        {
            throw new RuntimeException(exception.getMessage());
        }
    }
    throw new CertPathValidatorException("DSA parameters cannot be inherited from previous certificate.");
}
 
Example 17
Source File: JDKDSAPublicKey.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
JDKDSAPublicKey(
    DSAPublicKey    key)
{
    this.y = key.getY();
    this.dsaSpec = key.getParams();
}
 
Example 18
Source File: BCDSAPublicKey.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
BCDSAPublicKey(
    DSAPublicKey key)
{
    this.y = key.getY();
    this.dsaSpec = key.getParams();
}
 
Example 19
Source File: CertPathValidatorUtilities.java    From ripple-lib-java with ISC License 4 votes vote down vote up
/**
 * Return the next working key inheriting DSA parameters if necessary.
 * <p>
 * This methods inherits DSA parameters from the indexed certificate or
 * previous certificates in the certificate chain to the returned
 * <code>PublicKey</code>. The list is searched upwards, meaning the end
 * certificate is at position 0 and previous certificates are following.
 * </p>
 * <p>
 * If the indexed certificate does not contain a DSA key this method simply
 * returns the public key. If the DSA key already contains DSA parameters
 * the key is also only returned.
 * </p>
 *
 * @param certs The certification path.
 * @param index The index of the certificate which contains the public key
 *              which should be extended with DSA parameters.
 * @return The public key of the certificate in list position
 *         <code>index</code> extended with DSA parameters if applicable.
 * @throws AnnotatedException if DSA parameters cannot be inherited.
 */
protected static PublicKey getNextWorkingKey(List certs, int index)
    throws CertPathValidatorException
{
    Certificate cert = (Certificate)certs.get(index);
    PublicKey pubKey = cert.getPublicKey();
    if (!(pubKey instanceof DSAPublicKey))
    {
        return pubKey;
    }
    DSAPublicKey dsaPubKey = (DSAPublicKey)pubKey;
    if (dsaPubKey.getParams() != null)
    {
        return dsaPubKey;
    }
    for (int i = index + 1; i < certs.size(); i++)
    {
        X509Certificate parentCert = (X509Certificate)certs.get(i);
        pubKey = parentCert.getPublicKey();
        if (!(pubKey instanceof DSAPublicKey))
        {
            throw new CertPathValidatorException(
                "DSA parameters cannot be inherited from previous certificate.");
        }
        DSAPublicKey prevDSAPubKey = (DSAPublicKey)pubKey;
        if (prevDSAPubKey.getParams() == null)
        {
            continue;
        }
        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);
        }
        catch (Exception exception)
        {
            throw new RuntimeException(exception.getMessage());
        }
    }
    throw new CertPathValidatorException("DSA parameters cannot be inherited from previous certificate.");
}
 
Example 20
Source File: CertPathValidatorUtilities.java    From ripple-lib-java with ISC License 4 votes vote down vote up
/**
 * Return the next working key inheriting DSA parameters if necessary.
 * <p>
 * This methods inherits DSA parameters from the indexed certificate or
 * previous certificates in the certificate chain to the returned
 * <code>PublicKey</code>. The list is searched upwards, meaning the end
 * certificate is at position 0 and previous certificates are following.
 * </p>
 * <p>
 * If the indexed certificate does not contain a DSA key this method simply
 * returns the public key. If the DSA key already contains DSA parameters
 * the key is also only returned.
 * </p>
 *
 * @param certs The certification path.
 * @param index The index of the certificate which contains the public key
 *              which should be extended with DSA parameters.
 * @return The public key of the certificate in list position
 *         <code>index</code> extended with DSA parameters if applicable.
 * @throws AnnotatedException if DSA parameters cannot be inherited.
 */
protected static PublicKey getNextWorkingKey(List certs, int index, JcaJceHelper helper)
    throws CertPathValidatorException
{
    Certificate cert = (Certificate)certs.get(index);
    PublicKey pubKey = cert.getPublicKey();
    if (!(pubKey instanceof DSAPublicKey))
    {
        return pubKey;
    }
    DSAPublicKey dsaPubKey = (DSAPublicKey)pubKey;
    if (dsaPubKey.getParams() != null)
    {
        return dsaPubKey;
    }
    for (int i = index + 1; i < certs.size(); i++)
    {
        X509Certificate parentCert = (X509Certificate)certs.get(i);
        pubKey = parentCert.getPublicKey();
        if (!(pubKey instanceof DSAPublicKey))
        {
            throw new CertPathValidatorException(
                "DSA parameters cannot be inherited from previous certificate.");
        }
        DSAPublicKey prevDSAPubKey = (DSAPublicKey)pubKey;
        if (prevDSAPubKey.getParams() == null)
        {
            continue;
        }
        DSAParams dsaParams = prevDSAPubKey.getParams();
        DSAPublicKeySpec dsaPubKeySpec = new DSAPublicKeySpec(
            dsaPubKey.getY(), dsaParams.getP(), dsaParams.getQ(), dsaParams.getG());
        try
        {
            KeyFactory keyFactory = helper.createKeyFactory("DSA");
            return keyFactory.generatePublic(dsaPubKeySpec);
        }
        catch (Exception exception)
        {
            throw new RuntimeException(exception.getMessage());
        }
    }
    throw new CertPathValidatorException("DSA parameters cannot be inherited from previous certificate.");
}