else if (isCades && idSeq2.equals(SecurityIDs.ID_AA_SIGNING_CERTIFICATE_V1)) {
ASN1Set setout = (ASN1Set)seq2.getObjectAt(1);
ASN1Sequence seqout = (ASN1Sequence)setout.getObjectAt(0);
SigningCertificate sv2 = SigningCertificate.getInstance(seqout);
ESSCertID[] cerv2m = sv2.getCerts();
ESSCertID cerv2 = cerv2m[0];
byte[] enc2 = signCert.getEncoded();
MessageDigest m2 = new BouncyCastleDigest().getMessageDigest("SHA-1");
byte[] signCertHash = m2.digest(enc2);
byte[] hs2 = cerv2.getCertHash();
if (!Arrays.equals(signCertHash, hs2))
throw new IllegalArgumentException("Signing certificate doesn't match the ESS information.");
foundCades = true;
}
else if (isCades && idSeq2.equals(SecurityIDs.ID_AA_SIGNING_CERTIFICATE_V2)) {
ASN1Set setout = (ASN1Set)seq2.getObjectAt(1);
ASN1Sequence seqout = (ASN1Sequence)setout.getObjectAt(0);
SigningCertificateV2 sv2 = SigningCertificateV2.getInstance(seqout);
ESSCertIDv2[] cerv2m = sv2.getCerts();
ESSCertIDv2 cerv2 = cerv2m[0];
AlgorithmIdentifier ai2 = cerv2.getHashAlgorithm();
byte[] enc2 = signCert.getEncoded();
MessageDigest m2 = new BouncyCastleDigest().getMessageDigest(DigestAlgorithms.getDigest(ai2.getAlgorithm().getId()));
byte[] signCertHash = m2.digest(enc2);
byte[] hs2 = cerv2.getCertHash();
if (!Arrays.equals(signCertHash, hs2))
throw new IllegalArgumentException("Signing certificate doesn't match the ESS information.");
foundCades = true;
}
}