private static X509Certificate findRecipient(CertStore store)
throws CertStoreException {
boolean[] keyUsage = new boolean[KEY_USAGE_LENGTH];
keyUsage[KEY_ENCIPHERMENT] = true;
X509CertSelector signingSelector = new X509CertSelector();
signingSelector.setBasicConstraints(-2);
signingSelector.setKeyUsage(keyUsage);
LOGGER.debug("Selecting certificate with keyUsage:keyEncipherment");
Collection<? extends Certificate> certs = store
.getCertificates(signingSelector);
if (certs.size() > 0) {
LOGGER.debug(
"Found {} certificate(s) with keyUsage:keyEncipherment",
certs.size());
return (X509Certificate) certs.iterator().next();
} else {
LOGGER.debug("No certificates found.");
}
LOGGER.debug("Selecting certificate with keyUsage:dataEncipherment");
keyUsage = new boolean[KEY_USAGE_LENGTH];
keyUsage[DATA_ENCIPHERMENT] = true;
signingSelector.setKeyUsage(keyUsage);
certs = store.getCertificates(signingSelector);
if (certs.size() > 0) {
LOGGER.debug(
"Found {} certificate(s) with keyUsage:dataEncipherment",