Search in sources :

Example 6 with DSAKey

use of java.security.interfaces.DSAKey in project XobotOS by xamarin.

the class JDKDSASigner method engineInitVerify.

protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    CipherParameters param;
    // BEGIN android-added
    if (publicKey instanceof DSAKey) // END android-added
    {
        param = DSAUtil.generatePublicKeyParameter(publicKey);
    } else {
        try {
            byte[] bytes = publicKey.getEncoded();
            publicKey = JDKKeyFactory.createPublicKeyFromDERStream(bytes);
            if (publicKey instanceof DSAKey) {
                param = DSAUtil.generatePublicKeyParameter(publicKey);
            } else {
                throw new InvalidKeyException("can't recognise key type in DSA based signer");
            }
        } catch (Exception e) {
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        }
    }
    digest.reset();
    signer.init(false, param);
}
Also used : CipherParameters(org.bouncycastle.crypto.CipherParameters) DSAKey(java.security.interfaces.DSAKey) InvalidKeyException(java.security.InvalidKeyException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Example 7 with DSAKey

use of java.security.interfaces.DSAKey in project jdk8u_jdk by JetBrains.

the class DOMSignatureMethod method sign.

byte[] sign(Key key, SignedInfo si, XMLSignContext context) throws InvalidKeyException, XMLSignatureException {
    if (key == null || si == null) {
        throw new NullPointerException();
    }
    if (!(key instanceof PrivateKey)) {
        throw new InvalidKeyException("key must be PrivateKey");
    }
    checkKeySize(context, key);
    if (signature == null) {
        try {
            Provider p = (Provider) context.getProperty("org.jcp.xml.dsig.internal.dom.SignatureProvider");
            signature = (p == null) ? Signature.getInstance(getJCAAlgorithm()) : Signature.getInstance(getJCAAlgorithm(), p);
        } catch (NoSuchAlgorithmException nsae) {
            throw new XMLSignatureException(nsae);
        }
    }
    signature.initSign((PrivateKey) key);
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Signature provider:" + signature.getProvider());
        log.log(java.util.logging.Level.FINE, "Signing with key: " + key);
    }
    ((DOMSignedInfo) si).canonicalize(context, new SignerOutputStream(signature));
    try {
        Type type = getAlgorithmType();
        if (type == Type.DSA) {
            int size = ((DSAKey) key).getParams().getQ().bitLength();
            return JavaUtils.convertDsaASN1toXMLDSIG(signature.sign(), size / 8);
        } else if (type == Type.ECDSA) {
            return SignatureECDSA.convertASN1toXMLDSIG(signature.sign());
        } else {
            return signature.sign();
        }
    } catch (SignatureException se) {
        throw new XMLSignatureException(se);
    } catch (IOException ioe) {
        throw new XMLSignatureException(ioe);
    }
}
Also used : SignerOutputStream(org.jcp.xml.dsig.internal.SignerOutputStream) IOException(java.io.IOException) DSAKey(java.security.interfaces.DSAKey)

Example 8 with DSAKey

use of java.security.interfaces.DSAKey in project nhin-d by DirectProject.

the class SubjectPublicKeySizeField method injectReferenceValue.

/**
	 * {@inheritDoc}
	 */
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
    int retVal = 0;
    this.certificate = value;
    final PublicKey pubKey = this.certificate.getPublicKey();
    if (pubKey instanceof RSAKey) {
        retVal = ((RSAKey) pubKey).getModulus().bitLength();
    } else if (pubKey instanceof DSAKey) {
        retVal = ((DSAKey) pubKey).getParams().getP().bitLength();
    } else {
        // undertermined
        retVal = 0;
    }
    this.policyValue = PolicyValueFactory.getInstance(retVal);
}
Also used : RSAKey(java.security.interfaces.RSAKey) DSAKey(java.security.interfaces.DSAKey) PublicKey(java.security.PublicKey)

Aggregations

DSAKey (java.security.interfaces.DSAKey)8 IOException (java.io.IOException)4 DSAParams (java.security.interfaces.DSAParams)3 RSAKey (java.security.interfaces.RSAKey)3 InvalidKeyException (java.security.InvalidKeyException)2 PublicKey (java.security.PublicKey)2 SignatureException (java.security.SignatureException)2 ECKey (java.security.interfaces.ECKey)2 CipherParameters (org.bouncycastle.crypto.CipherParameters)2 SignerOutputStream (org.jcp.xml.dsig.internal.SignerOutputStream)2 ApkVerifier (com.android.apksig.ApkVerifier)1 MinSdkVersionException (com.android.apksig.apk.MinSdkVersionException)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 KeyPairGenerator (java.security.KeyPairGenerator)1 MessageDigest (java.security.MessageDigest)1 X509Certificate (java.security.cert.X509Certificate)1 DSAParameterSpec (java.security.spec.DSAParameterSpec)1 SecretKey (javax.crypto.SecretKey)1 DHKey (javax.crypto.interfaces.DHKey)1