Refine search
public byte[] getEncoded() throws CertificateEncodingException { try { return cert.getEncoded(); } catch (java.security.cert.CertificateEncodingException e) { throw new CertificateEncodingException(e.getMessage()); } }
X509Certificate cert = new JcaX509CertificateConverter().setProvider(BC) .getCertificate(certGen.build(sigGen)); cert.checkValidity(new Date()); cert.verify(cert.getPublicKey()); throw new CertificateEncodingException("Error during creation of self-signed Certificate: " + ioe.getMessage(), ioe);
issuerName = certificate.getIssuerDN().getName().replace(",", ", "); } else { issuerName = certificate.getIssuerX500Principal().toString(); issuerSerial.setX509SerialNumber(certificate.getSerialNumber()); } catch (CertificateEncodingException e) { throw new RuntimeException("certificate encoding error: " + e.getMessage(), e);
@Override public ASN1Set getValue() { SigningCertificate attribute = (SigningCertificate) super.getAttribute(); X509Certificate cert = attribute.getValue(); Digest digest = DigestFactory.getInstance().factoryDefault(); digest.setAlgorithm(DigestAlgorithmEnum.SHA_1); byte[] certHash = null; try { certHash = digest.digest(cert.getEncoded()); } catch (CertificateEncodingException ex) { ex.printStackTrace(); } X509Name dirName = new X509Name(cert.getSubjectDN().getName()); GeneralName name = new GeneralName(dirName); GeneralNames issuer = new GeneralNames(name); DERInteger serialNumber = new DERInteger(cert.getSerialNumber()); IssuerSerial issuerSerial = new IssuerSerial(issuer, serialNumber); ESSCertID essCertId = new ESSCertID(certHash, issuerSerial); return new DERSet(new DERSequence(new ASN1Encodable[]{new DERSequence(essCertId), new DERSequence(new DERNull())})); } }
public HashMap<String,String> getCertificateInfo(X509Certificate cert){ HashMap<String,String> certInfo = new HashMap<String,String>(); X500Name x500name; try { x500name = new JcaX509CertificateHolder(cert).getSubject(); } catch (CertificateEncodingException e) { e.printStackTrace(); return certInfo; } certInfo.put(CertManagerConstants.SUBJECT_NAME,cert.getSubjectDN().getName()); certInfo.put(CertManagerConstants.ISSUER_NAME,cert.getIssuerDN().getName()); certInfo.put(CertManagerConstants.SN, cert.getSerialNumber().toString()); RDN cn = x500name.getRDNs(BCStyle.CN)[0]; certInfo.put(CertManagerConstants.CN,cn.toString()); RDN ou = x500name.getRDNs(BCStyle.OU)[0]; certInfo.put(CertManagerConstants.OU,ou.toString()); certInfo.put(CertManagerConstants.START_DATE,cert.getNotBefore().toString()); certInfo.put(CertManagerConstants.EXPIRY_DATE,cert.getNotAfter().toString()); return certInfo; }
private String generateCSR(X509Certificate cert, PrivateKey signingKey) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, KeyStoreException, IOException { String sigalg = cert.getSigAlgName(); X509Name subject; try{ ASN1InputStream ais = new ASN1InputStream(cert.getEncoded()); X509CertificateStructure x509Struct = new X509CertificateStructure((ASN1Sequence)ais.readObject()); ais.close(); subject = x509Struct.getSubject(); } catch(CertificateEncodingException e) { log.warn(e.toString()+" while retrieving subject from certificate to create CSR. Using subjectDN instead."); subject = new X509Name(cert.getSubjectDN().toString()); PublicKey publicKey = cert.getPublicKey();
private void writeCertList(BufferedSink sink, List<Certificate> certificates) throws IOException { try { sink.writeDecimalLong(certificates.size()) .writeByte('\n'); for (int i = 0, size = certificates.size(); i < size; i++) { byte[] bytes = certificates.get(i).getEncoded(); String line = ByteString.of(bytes).base64(); sink.writeUtf8(line) .writeByte('\n'); } } catch (CertificateEncodingException e) { throw new IOException(e.getMessage()); } }
public String getFingerPrint(Certificate cert) throws KeyStoreException { if (!(cert instanceof X509Certificate)) { return null; } StringBuffer buff = new StringBuffer(); X509Certificate x509 = (X509Certificate) cert; try { String fingerprint = Encoding.hashMD5(cert.getEncoded()); for (int i = 0; i < fingerprint.length(); i += 2) { buff.append(fingerprint.substring(i, i + 1)).append(":"); } buff.deleteCharAt(buff.length() - 1); } catch (CertificateEncodingException e) { throw new KeyStoreException(e.getMessage()); } String dn = x509.getSubjectDN().getName(); log.info("Fingerprint is " + buff.toString().toUpperCase()); return buff.toString().toUpperCase() + " " + dn; }
private void encodeCertificate( Certificate cert, DataOutputStream dOut) throws IOException { try { byte[] cEnc = cert.getEncoded(); dOut.writeUTF(cert.getType()); dOut.writeInt(cEnc.length); dOut.write(cEnc); } catch (CertificateEncodingException ex) { throw new IOException(ex.toString()); } }
"Failed to sign using signer \"" + signerName + "\"", e); } catch (CertificateEncodingException e) { throw new CertificateEncodingException( "Failed to sign using signer \"" + signerName + "\"", e); } catch (SignatureException e) { PublicKey publicKey = signerConfig.certificates.get(0).getPublicKey(); String signatureBlockFileName = "META-INF/" + signerName + "."
private void addCertTLV(Integer type, X509Certificate cert) { byte[] certDer = null; try { certDer = cert.getEncoded(); } catch (CertificateEncodingException e) { log.error("Failed to add DER TLV type "+type); e.printStackTrace(); } this.addTLV(new TLV (type, certDer, certDer.length)); }
@Test public void getAttestationReturnsUnknownIfFingerprintEncodingFails() throws Exception { MetadataService service = new MetadataService(); final X509Certificate attestationCert = mock(X509Certificate.class); when(attestationCert.getEncoded()).thenThrow(new CertificateEncodingException("Forced failure")); Attestation attestation = service.getAttestation(attestationCert); assertFalse(attestation.isTrusted()); }
try { MessageDigest md = MessageDigest.getInstance("SHA1"); byte[] publicKey = md.digest(c.getEncoded()); hexString = byte2HexFormatted(publicKey); } catch (NoSuchAlgorithmException e1) { Log.e(TAG, e1.toString(), e1); } catch (CertificateEncodingException e) { Log.e(TAG, e.toString(), e);
protected void encodePayload() throws IOException { try { payload = certificate.getEncoded(); } catch (CertificateEncodingException cee) { throw new IOException(cee.toString()); } } }
public static OpenSSLX509Certificate fromCertificate(Certificate cert) throws CertificateEncodingException { if (cert instanceof OpenSSLX509Certificate) { return (OpenSSLX509Certificate) cert; } else if (cert instanceof X509Certificate) { return fromX509Der(cert.getEncoded()); } else { throw new CertificateEncodingException("Only X.509 certificates are supported"); } }
private void saveSignerInfo(SignerInfo signerInfo, DataOutputStream os, List<SignerInfo> saveContext) throws IOException { int cacheIdx = saveContext.indexOf(signerInfo); os.writeInt(cacheIdx); if (cacheIdx >= 0) return; Certificate[] certs = signerInfo.getCertificateChain(); int anchorIndex = -1; os.writeInt(certs == null ? 0 : certs.length); if (certs != null) for (int i = 0; i < certs.length; i++) { if (certs[i].equals(signerInfo.getTrustAnchor())) anchorIndex = i; byte[] certBytes; try { certBytes = certs[i].getEncoded(); } catch (CertificateEncodingException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } os.writeInt(certBytes.length); os.write(certBytes); } os.writeInt(anchorIndex); os.writeUTF(signerInfo.getMessageDigestAlgorithm()); saveContext.add(signerInfo); }
/** * @see java.security.cert.CertPath#getEncoded(String) */ @Override public byte[] getEncoded(String encoding) throws CertificateEncodingException { final Encoding encType = Encoding.findByApiName(encoding); if (encType == null) { throw new CertificateEncodingException("Unsupported encoding: " + encoding); } return getEncoded(encType); }
private static byte[] getCoreExtValue(X509Certificate cert, ASN1ObjectIdentifier type) throws CertificateEncodingException { requireNonNull("cert", cert); requireNonNull("type", type); byte[] fullExtValue = cert.getExtensionValue(type.getId()); if (fullExtValue == null) { return null; } try { return ASN1OctetString.getInstance(fullExtValue).getOctets(); } catch (IllegalArgumentException ex) { throw new CertificateEncodingException("invalid extension " + type.getId() + ": " + ex.getMessage()); } }
/** * Returns the private key signature on JBMR2+ or else null. */ public static String getSigningKey(String alias) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { Certificate cert = getPrivateKeyEntry(alias).getCertificate(); if (cert == null) { return null; } try { return Base64.encodeToString(cert.getEncoded(), Base64.NO_WRAP); } catch (CertificateEncodingException e) { e.printStackTrace(); return null; } } else { return null; } }
public static String getCommonName(X509Certificate cert) { try { return getValueByObjectIdentifier(cert, BCStyle.CN); } catch (CertificateEncodingException e) { LOGGER.error("Error extracting common name from certificate", e.getMessage(), e); return null; } }