List of usage examples for java.security.cert X509Certificate getSignature
public abstract byte[] getSignature();
From source file:org.cesecore.util.CertTools.java
/** * Gets the signature value (the raw signature bits) from the certificate. For an X509 certificate this is the ASN.1 definition which is: * signature BIT STRING/*from w w w. j a va 2 s .co m*/ * * @param cert Certificate * * @return byte[] containing the certificate signature bits, if cert is null a byte[] of size 0 is returned. */ public static byte[] getSignature(Certificate cert) { byte[] ret = null; if (cert == null) { ret = new byte[0]; } else { if (cert instanceof X509Certificate) { X509Certificate xcert = (X509Certificate) cert; ret = xcert.getSignature(); } else if (StringUtils.equals(cert.getType(), "CVC")) { CardVerifiableCertificate cvccert = (CardVerifiableCertificate) cert; try { ret = cvccert.getCVCertificate().getSignature(); } catch (NoSuchFieldException e) { log.error("NoSuchFieldException: ", e); return null; } } } return ret; }
From source file:org.signserver.admin.gui.ViewCertificateFrame.java
private void viewCertificate(final X509Certificate certificate) { this.certificate = certificate; if (certificate == null) { fields = null;/* w w w. j a v a 2s . com*/ } else { fields = new ArrayList<Field>(); fields.add(new Field("Version", String.valueOf(certificate.getVersion()))); fields.add(new Field("Serial Number", certificate.getSerialNumber().toString(16))); fields.add(new Field("Certificate Signature Algorithm", String.valueOf(certificate.getSigAlgName()))); fields.add(new Field("Issuer", String.valueOf(certificate.getIssuerDN()))); fields.add(new Field("Validity Not Before", String.valueOf(certificate.getNotBefore()))); fields.add(new Field("Validity Not After", String.valueOf(certificate.getNotAfter()))); fields.add(new Field("Subject", String.valueOf(certificate.getSubjectDN()))); fields.add(new Field("Subject Public Key Algorithm", String.valueOf(certificate.getPublicKey().getAlgorithm()))); fields.add(new Field("Subject's Public Key", new String(Hex.encode(certificate.getPublicKey().getEncoded())))); if (certificate.getCriticalExtensionOIDs() != null) { for (String extensionOid : certificate.getCriticalExtensionOIDs()) { fields.add(new Field("Critical extension: " + extensionOid, "<Not supported yet>")); } } if (certificate.getNonCriticalExtensionOIDs() != null) { for (String extensionOid : certificate.getNonCriticalExtensionOIDs()) { fields.add(new Field("Non critical extension: " + extensionOid, "<Not supported yet>")); } } fields.add(new Field("Certificate Signature Algorithm", String.valueOf(certificate.getSigAlgName()))); fields.add( new Field("Certificate Signature Value", new String(Hex.encode(certificate.getSignature())))); fieldsList.setModel(new AbstractListModel() { @Override public int getSize() { return fields.size(); } @Override public Object getElementAt(int index) { return fields.get(index); } }); } }
From source file:test.integ.be.fedict.trust.Foreigner201305Test.java
@Test public void testForeigner201305() throws Exception { CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate rootCert = (X509Certificate) certificateFactory .generateCertificate(Foreigner201305Test.class.getResourceAsStream("/belgiumrca2.crt")); X509Certificate foreigner201304Cert = (X509Certificate) certificateFactory .generateCertificate(Foreigner201305Test.class.getResourceAsStream("/foreigner201304.crt")); foreigner201304Cert.verify(rootCert.getPublicKey()); X509Certificate foreigner201305Cert = (X509Certificate) certificateFactory .generateCertificate(Foreigner201305Test.class.getResourceAsStream("/foreigner201305.crt")); foreigner201305Cert.verify(rootCert.getPublicKey()); byte[] foreigner201304SignatureValue = foreigner201304Cert.getSignature(); byte[] foreigner201305SignatureValue = foreigner201305Cert.getSignature(); LOG.debug("201304 signature size: " + foreigner201304SignatureValue.length); LOG.debug("201305 signature size: " + foreigner201305SignatureValue.length); RSAPublicKey rootPublicKey = (RSAPublicKey) rootCert.getPublicKey(); BigInteger foreigner201304Signature = new BigInteger(foreigner201304SignatureValue); BigInteger foreigner201305Signature = new BigInteger(foreigner201305SignatureValue); LOG.debug("201305 signature size: " + foreigner201305Signature.toByteArray().length); BigInteger foreigner201304PaddedMessage = foreigner201304Signature.modPow(rootPublicKey.getPublicExponent(), rootPublicKey.getModulus()); BigInteger foreigner201305PaddedMessage = foreigner201305Signature.modPow(rootPublicKey.getPublicExponent(), rootPublicKey.getModulus()); LOG.debug(//from w w w . j a v a 2s. co m "201304 padded message: " + new String(Hex.encodeHex(foreigner201304PaddedMessage.toByteArray()))); LOG.debug( "201305 padded message: " + new String(Hex.encodeHex(foreigner201305PaddedMessage.toByteArray()))); LOG.debug("201304 modulus size: " + ((RSAPublicKey) foreigner201304Cert.getPublicKey()).getModulus().toByteArray().length); LOG.debug("201305 modulus size: " + ((RSAPublicKey) foreigner201305Cert.getPublicKey()).getModulus().toByteArray().length); LOG.debug("201304 modulus: " + new String( Hex.encodeHex(((RSAPublicKey) foreigner201304Cert.getPublicKey()).getModulus().toByteArray()))); LOG.debug("201305 modulus: " + new String( Hex.encodeHex(((RSAPublicKey) foreigner201305Cert.getPublicKey()).getModulus().toByteArray()))); }
From source file:test.integ.be.fedict.trust.Foreigner201305Test.java
/** * wget --recursive -e robots=off http://certs.eid.belgium.be * // www.j a va 2s . co m * @throws Exception */ @Test public void testAllCertificateAuthorities() throws Exception { File dirFile = new File("/home/fcorneli/certs/certs.eid.belgium.be"); LOG.debug("directory: " + dirFile.getAbsolutePath()); File[] certFiles = dirFile.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { LOG.debug(name); return name.endsWith("crt"); } }); CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); for (File certFile : certFiles) { X509Certificate certificate = (X509Certificate) certificateFactory .generateCertificate(new FileInputStream(certFile)); LOG.debug("certificate: " + certificate.getSubjectX500Principal()); RSAPublicKey rsaPublicKey = (RSAPublicKey) certificate.getPublicKey(); int modulusSize = rsaPublicKey.getModulus().toByteArray().length; LOG.debug("modulus size: " + modulusSize); int signatureSize = certificate.getSignature().length; LOG.debug("signature size: " + signatureSize); assertEquals(modulusSize - 1, signatureSize); } LOG.debug("total number of CAs: " + certFiles.length); }