use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class SignatureBaseRSA method engineInitSign.
/**
* {@inheritDoc}
*/
protected void engineInitSign(Key privateKey, SecureRandom secureRandom) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = null;
if (privateKey != null) {
supplied = privateKey.getClass().getName();
}
String needed = PrivateKey.class.getName();
Object[] exArgs = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
if (secureRandom == null) {
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} else {
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
}
} catch (InvalidKeyException ex) {
throw new XMLSignatureException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class SignatureECDSA method engineInitSign.
/**
* {@inheritDoc}
*/
protected void engineInitSign(Key privateKey, SecureRandom secureRandom) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = null;
if (privateKey != null) {
supplied = privateKey.getClass().getName();
}
String needed = PrivateKey.class.getName();
Object[] exArgs = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
if (secureRandom == null) {
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} else {
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
}
} catch (InvalidKeyException ex) {
throw new XMLSignatureException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class IntegrityHmac method engineSign.
/**
* Proxy method for {@link java.security.Signature#sign()}
* which is executed on the internal {@link java.security.Signature} object.
*
* @return the result of the {@link java.security.Signature#sign()} method
* @throws XMLSignatureException
*/
protected byte[] engineSign() throws XMLSignatureException {
try {
if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
LOG.debug("HMACOutputLength must not be less than {}", getDigestLength());
Object[] exArgs = { String.valueOf(getDigestLength()) };
throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
} else {
return this.macAlgorithm.doFinal();
}
} catch (IllegalStateException ex) {
throw new XMLSignatureException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class SignatureDSA method engineInitSign.
/**
* {@inheritDoc}
*/
protected void engineInitSign(Key privateKey, SecureRandom secureRandom) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = null;
if (privateKey != null) {
supplied = privateKey.getClass().getName();
}
String needed = PrivateKey.class.getName();
Object[] exArgs = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
if (secureRandom == null) {
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} else {
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
}
} catch (InvalidKeyException ex) {
throw new XMLSignatureException(ex);
}
size = ((DSAKey) privateKey).getParams().getQ().bitLength();
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class SignatureDSA method engineInitVerify.
/**
* {@inheritDoc}
*/
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) {
String supplied = null;
if (publicKey != null) {
supplied = publicKey.getClass().getName();
}
String needed = PublicKey.class.getName();
Object[] exArgs = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this.signatureAlgorithm;
try {
this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
LOG.debug("Exception when reinstantiating Signature: {}", e);
this.signatureAlgorithm = sig;
}
throw new XMLSignatureException(ex);
}
size = ((DSAKey) publicKey).getParams().getQ().bitLength();
}
Aggregations