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);
}
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);
}
}
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);
}
Aggregations