for (X509Certificate cert : chain) {
CertificateInfo certificateInfo = new CertificateInfo();
certificateInfo.setSubjectDN(Certificates.getSubject(cert));
Md5Hash hash = OpenSshUtils.getSignature(cert.getPublicKey());
certificateInfo.setPublicKeyHash(hash.toHex());
byte[] data = cert.getPublicKey().getEncoded();
certificateInfo.setPublicKey(Hex.toHex(data));
certificates.add(certificateInfo);