use of java.security.SignatureException in project robovm by robovm.
the class DSABase method engineSign.
protected byte[] engineSign() throws SignatureException {
byte[] hash = new byte[digest.getDigestSize()];
digest.doFinal(hash, 0);
try {
BigInteger[] sig = signer.generateSignature(hash);
return encoder.encode(sig[0], sig[1]);
} catch (Exception e) {
throw new SignatureException(e.toString());
}
}
use of java.security.SignatureException in project robovm by robovm.
the class DSASigner method engineVerify.
protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
byte[] hash = new byte[digest.getDigestSize()];
digest.doFinal(hash, 0);
BigInteger[] sig;
try {
sig = derDecode(sigBytes);
} catch (Exception e) {
throw new SignatureException("error decoding signature bytes.");
}
return signer.verifySignature(hash, sig[0], sig[1]);
}
use of java.security.SignatureException in project robovm by robovm.
the class OpenSSLX509Certificate method verifyInternal.
private void verifyInternal(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
String sigAlg = getSigAlgName();
if (sigAlg == null) {
sigAlg = getSigAlgOID();
}
final Signature sig;
if (sigProvider == null) {
sig = Signature.getInstance(sigAlg);
} else {
sig = Signature.getInstance(sigAlg, sigProvider);
}
sig.initVerify(key);
sig.update(getTBSCertificate());
if (!sig.verify(getSignature())) {
throw new SignatureException("signature did not verify");
}
}
use of java.security.SignatureException in project robovm by robovm.
the class SignatureTest method testVerify_NONEwithRSA_Key_SignatureTooLarge_Failure.
public void testVerify_NONEwithRSA_Key_SignatureTooLarge_Failure() throws Exception {
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
PublicKey pubKey = kf.generatePublic(pubKeySpec);
Signature sig = Signature.getInstance("NONEwithRSA");
sig.initVerify(pubKey);
sig.update(Vector1Data);
byte[] invalidSignature = new byte[NONEwithRSA_Vector1Signature.length * 2];
System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature, 0, NONEwithRSA_Vector1Signature.length);
System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature, NONEwithRSA_Vector1Signature.length, NONEwithRSA_Vector1Signature.length);
try {
sig.verify(invalidSignature);
fail("Should throw exception when signature is too large");
} catch (SignatureException expected) {
}
}
use of java.security.SignatureException in project robovm by robovm.
the class X509CRLObject method verify.
public void verify(PublicKey key, String sigProvider) throws CRLException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
if (!c.getSignatureAlgorithm().equals(c.getTBSCertList().getSignature())) {
throw new CRLException("Signature algorithm on CertificateList does not match TBSCertList.");
}
Signature sig;
if (sigProvider != null) {
sig = Signature.getInstance(getSigAlgName(), sigProvider);
} else {
sig = Signature.getInstance(getSigAlgName());
}
sig.initVerify(key);
sig.update(this.getTBSCertList());
if (!sig.verify(this.getSignature())) {
throw new SignatureException("CRL does not verify with supplied public key.");
}
}
Aggregations