use of org.bouncycastle.operator.RuntimeOperatorException in project dgc-gateway by eu-digital-green-certificates.
the class SignerInformationService method certificateSignedByCa.
private boolean certificateSignedByCa(X509CertificateHolder certificate, TrustedPartyEntity caCertificateEntity) {
X509Certificate caCertificate = trustedPartyService.getX509CertificateFromEntity(caCertificateEntity);
ContentVerifierProvider verifier;
try {
verifier = new JcaContentVerifierProviderBuilder().build(caCertificate);
} catch (OperatorCreationException e) {
DgcMdc.put("certHash", caCertificateEntity.getThumbprint());
log.error("Failed to instantiate JcaContentVerifierProvider from cert");
return false;
}
try {
return certificate.isSignatureValid(verifier);
} catch (CertException | RuntimeOperatorException e) {
return false;
}
}
use of org.bouncycastle.operator.RuntimeOperatorException in project xipki by xipki.
the class FpIdCalculator method hash.
/**
* Hash the data and returns the first 8 bytes of the hash value.
* @param data data over which the hash value is calculated.
* @return long represented of the first 8 bytes
*/
public static long hash(byte[] data) {
ParamUtil.requireNonNull("data", data);
ConcurrentBagEntry<Digest> md0 = null;
for (int i = 0; i < 3; i++) {
try {
md0 = MDS.borrow(10, TimeUnit.SECONDS);
break;
} catch (InterruptedException ex) {
// CHECKSTYLE:SKIP
}
}
if (md0 == null) {
throw new RuntimeOperatorException("could not get idle MessageDigest");
}
try {
Digest md = md0.value();
md.reset();
md.update(data, 0, data.length);
byte[] bytes = new byte[md.getDigestSize()];
md.doFinal(bytes, 0);
return bytesToLong(bytes);
} finally {
MDS.requite(md0);
}
}
use of org.bouncycastle.operator.RuntimeOperatorException in project xipki by xipki.
the class HashCalculator method hash.
public static byte[] hash(HashAlgo hashAlgo, byte[]... datas) {
notNull(hashAlgo, "hashAlgo");
notNull(datas, "datas");
if (!MDS_MAP.containsKey(hashAlgo)) {
throw new IllegalArgumentException("unknown hash algo " + hashAlgo);
}
ConcurrentBag<ConcurrentBagEntry<Digest>> mds = MDS_MAP.get(hashAlgo);
ConcurrentBagEntry<Digest> md0 = null;
for (int i = 0; i < 3; i++) {
try {
md0 = mds.borrow(10, TimeUnit.SECONDS);
break;
} catch (InterruptedException ex) {
// CHECKSTYLE:SKIP
}
}
if (md0 == null) {
throw new RuntimeOperatorException("could not get idle MessageDigest");
}
try {
Digest md = md0.value();
md.reset();
for (byte[] data : datas) {
if (data != null && data.length > 0) {
md.update(data, 0, data.length);
}
}
byte[] bytes = new byte[md.getDigestSize()];
md.doFinal(bytes, 0);
return bytes;
} finally {
mds.requite(md0);
}
}
use of org.bouncycastle.operator.RuntimeOperatorException in project xipki by xipki.
the class HashCalculator method hash.
// method hash
public static byte[] hash(HashAlgo hashAlgo, byte[] data, int offset, int len) {
notNull(hashAlgo, "hashAlgo");
notNull(data, "data");
if (data.length - offset < len) {
throw new IndexOutOfBoundsException("data.length - offset < len");
}
if (!MDS_MAP.containsKey(hashAlgo)) {
throw new IllegalArgumentException("unknown hash algo " + hashAlgo);
}
ConcurrentBag<ConcurrentBagEntry<Digest>> mds = MDS_MAP.get(hashAlgo);
ConcurrentBagEntry<Digest> md0 = null;
for (int i = 0; i < 3; i++) {
try {
md0 = mds.borrow(10, TimeUnit.SECONDS);
break;
} catch (InterruptedException ex) {
// CHECKSTYLE:SKIP
}
}
if (md0 == null) {
throw new RuntimeOperatorException("could not get idle MessageDigest");
}
try {
Digest md = md0.value();
md.reset();
md.update(data, offset, len);
byte[] bytes = new byte[md.getDigestSize()];
md.doFinal(bytes, 0);
return bytes;
} finally {
mds.requite(md0);
}
}
Aggregations