private static X509Certificate getCertificate(PublicKey pk, KeyStore store) throws IOException {
try {
Enumeration<String> aliases = store.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Certificate cert = store.getCertificate(alias);
if (cert == null || !X_509_CERTIFICATE_TYPE.equals(cert.getType())) {
continue;
}
X509Certificate x509Cert = (X509Certificate) cert;
if (x509Cert.getPublicKey().equals(pk)) {
return x509Cert;