use of java.security.SignatureException in project robovm by robovm.
the class X509V2AttributeCertificate method verify.
public final void verify(PublicKey key, String provider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
Signature signature = null;
if (!cert.getSignatureAlgorithm().equals(cert.getAcinfo().getSignature())) {
throw new CertificateException("Signature algorithm in certificate info not same as outer certificate");
}
signature = Signature.getInstance(cert.getSignatureAlgorithm().getObjectId().getId(), provider);
signature.initVerify(key);
try {
signature.update(cert.getAcinfo().getEncoded());
} catch (IOException e) {
throw new SignatureException("Exception encoding certificate info object");
}
if (!signature.verify(this.getSignature())) {
throw new InvalidKeyException("Public key presented not for certificate signature");
}
}
use of java.security.SignatureException in project robovm by robovm.
the class X509CertificateObject method verify.
public final void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
Signature signature;
String sigName = X509SignatureUtil.getSignatureName(c.getSignatureAlgorithm());
try {
signature = Signature.getInstance(sigName, BouncyCastleProvider.PROVIDER_NAME);
} catch (Exception e) {
signature = Signature.getInstance(sigName);
}
checkSignature(key, signature);
}
use of java.security.SignatureException in project robovm by robovm.
the class SignatureSpiTest method testEngineSign_BII.
public void testEngineSign_BII() {
MySignature signature = new MySignature("dummy");
try {
signature.initSign(new PrivateKey() {
public String getFormat() {
return null;
}
public byte[] getEncoded() {
return null;
}
public String getAlgorithm() {
return null;
}
});
} catch (InvalidKeyException e) {
fail("unexpected exception: " + e);
}
byte[] buf = new byte[10];
try {
signature.sign(buf, 2, 1);
assertTrue("SPI method not called", signature.wasMethodCalled("engineSign_[BII"));
} catch (SignatureException e) {
fail("unexpected exception: " + e);
}
}
use of java.security.SignatureException in project robovm by robovm.
the class SignatureSpiTest method testEngineVerify_BII.
public void testEngineVerify_BII() {
MySignature signature = new MySignature("dummy");
try {
signature.initVerify(new PublicKey() {
public String getFormat() {
return null;
}
public byte[] getEncoded() {
return null;
}
public String getAlgorithm() {
return null;
}
});
} catch (InvalidKeyException e) {
fail("unexpected exception");
}
byte[] buf = new byte[10];
try {
signature.verify(buf, 2, 5);
signature.wasMethodCalled("engineVerify_[BII");
} catch (SignatureException e) {
fail("unexpected exception");
}
}
use of java.security.SignatureException in project robovm by robovm.
the class SignatureTest method testUpdatebyte.
/*
* Class under test for void update(byte)
*/
public void testUpdatebyte() throws Exception {
MySignature1 s = new MySignature1("ABC");
try {
s.update((byte) 1);
fail("No expected SignatureException");
} catch (SignatureException e) {
}
s.initVerify(new MyPublicKey());
s.update((byte) 1);
s.initSign(new MyPrivateKey());
s.update((byte) 1);
assertEquals("state", MySignature1.SIGN, s.getState());
assertTrue("update() failed", s.runEngineUpdate1);
try {
Signature sig = getTestSignature();
sig.update((byte) 42);
fail("expected SignatureException");
} catch (SignatureException e) {
// ok
}
}
Aggregations