Java Code Examples for java.security.cert.CertPath#getEncoded()
The following examples show how to use
java.security.cert.CertPath#getEncoded() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CertPathEncodingTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Make the CertPath whose encoded form has already been stored CertificateFactory certFac = CertificateFactory.getInstance("X509"); final List<Certificate> certs = new ArrayList<>(); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes()))); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes()))); CertPath cp = certFac.generateCertPath(certs); // Get the encoded form of the CertPath we made byte[] encoded = cp.getEncoded("PKCS7"); // check if it matches the encoded value if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) { throw new RuntimeException("PKCS#7 encoding doesn't match stored value"); } // Generate a CertPath from the encoded value and check if it equals // the CertPath generated from the certificates CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7"); if (!decodedCP.equals(cp)) { throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original"); } }
Example 2
Source File: CertPathEncodingTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Make the CertPath whose encoded form has already been stored CertificateFactory certFac = CertificateFactory.getInstance("X509"); final List<Certificate> certs = new ArrayList<>(); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes()))); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes()))); CertPath cp = certFac.generateCertPath(certs); // Get the encoded form of the CertPath we made byte[] encoded = cp.getEncoded("PKCS7"); // check if it matches the encoded value if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) { throw new RuntimeException("PKCS#7 encoding doesn't match stored value"); } // Generate a CertPath from the encoded value and check if it equals // the CertPath generated from the certificates CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7"); if (!decodedCP.equals(cp)) { throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original"); } }
Example 3
Source File: CertPathEncodingTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Make the CertPath whose encoded form has already been stored CertificateFactory certFac = CertificateFactory.getInstance("X509"); final List<Certificate> certs = new ArrayList<>(); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes()))); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes()))); CertPath cp = certFac.generateCertPath(certs); // Get the encoded form of the CertPath we made byte[] encoded = cp.getEncoded("PKCS7"); // check if it matches the encoded value if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) { throw new RuntimeException("PKCS#7 encoding doesn't match stored value"); } // Generate a CertPath from the encoded value and check if it equals // the CertPath generated from the certificates CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7"); if (!decodedCP.equals(cp)) { throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original"); } }
Example 4
Source File: CertPathEncodingTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Make the CertPath whose encoded form has already been stored CertificateFactory certFac = CertificateFactory.getInstance("X509"); final List<Certificate> certs = new ArrayList<>(); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes()))); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes()))); CertPath cp = certFac.generateCertPath(certs); // Get the encoded form of the CertPath we made byte[] encoded = cp.getEncoded("PKCS7"); // check if it matches the encoded value if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) { throw new RuntimeException("PKCS#7 encoding doesn't match stored value"); } // Generate a CertPath from the encoded value and check if it equals // the CertPath generated from the certificates CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7"); if (!decodedCP.equals(cp)) { throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original"); } }
Example 5
Source File: CertPathEncodingTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Make the CertPath whose encoded form has already been stored CertificateFactory certFac = CertificateFactory.getInstance("X509"); final List<Certificate> certs = new ArrayList<>(); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes()))); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes()))); CertPath cp = certFac.generateCertPath(certs); // Get the encoded form of the CertPath we made byte[] encoded = cp.getEncoded("PKCS7"); // check if it matches the encoded value if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) { throw new RuntimeException("PKCS#7 encoding doesn't match stored value"); } // Generate a CertPath from the encoded value and check if it equals // the CertPath generated from the certificates CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7"); if (!decodedCP.equals(cp)) { throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original"); } }
Example 6
Source File: CertPathEncodingTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Make the CertPath whose encoded form has already been stored CertificateFactory certFac = CertificateFactory.getInstance("X509"); final List<Certificate> certs = new ArrayList<>(); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes()))); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes()))); CertPath cp = certFac.generateCertPath(certs); // Get the encoded form of the CertPath we made byte[] encoded = cp.getEncoded("PKCS7"); // check if it matches the encoded value if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) { throw new RuntimeException("PKCS#7 encoding doesn't match stored value"); } // Generate a CertPath from the encoded value and check if it equals // the CertPath generated from the certificates CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7"); if (!decodedCP.equals(cp)) { throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original"); } }
Example 7
Source File: CertPathEncodingTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Make the CertPath whose encoded form has already been stored CertificateFactory certFac = CertificateFactory.getInstance("X509"); final List<Certificate> certs = new ArrayList<>(); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes()))); certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes()))); CertPath cp = certFac.generateCertPath(certs); // Get the encoded form of the CertPath we made byte[] encoded = cp.getEncoded("PKCS7"); // check if it matches the encoded value if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) { throw new RuntimeException("PKCS#7 encoding doesn't match stored value"); } // Generate a CertPath from the encoded value and check if it equals // the CertPath generated from the certificates CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7"); if (!decodedCP.equals(cp)) { throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original"); } }
Example 8
Source File: X509CertUtil.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
/** * PKCS #7 encode a number of certificates. * * @return The encoding * @param certs * The certificates * @throws CryptoException * If there was a problem encoding the certificates */ public static byte[] getCertsEncodedPkcs7(X509Certificate[] certs) throws CryptoException { try { ArrayList<Certificate> encodedCerts = new ArrayList<>(); Collections.addAll(encodedCerts, certs); CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce()); CertPath cp = cf.generateCertPath(encodedCerts); return cp.getEncoded(PKCS7_ENCODING); } catch (CertificateException | NoSuchProviderException e) { throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e); } }
Example 9
Source File: X509CertUtil.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
/** * PKI Path encode a number of certificates. * * @return The encoding * @param certs * The certificates * @throws CryptoException * If there was a problem encoding the certificates */ public static byte[] getCertsEncodedPkiPath(X509Certificate[] certs) throws CryptoException { try { ArrayList<Certificate> encodedCerts = new ArrayList<>(); Collections.addAll(encodedCerts, certs); CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce()); CertPath cp = cf.generateCertPath(encodedCerts); return cp.getEncoded(PKI_PATH_ENCODING); } catch (CertificateException | NoSuchProviderException e) { throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e); } }
Example 10
Source File: Base64Utils.java From signer with GNU Lesser General Public License v3.0 | 5 votes |
/** * * Performs the encoding of a certificate chain to base64 * * @param aCertificationChain certificate chain * @return ASN.1 DER encoded on Base64, for X.509 certificate * @throws CertificateException exception */ public static String encodeX509CertChainToBase64(Certificate[] aCertificationChain) throws CertificateException { List<Certificate> certList = Arrays.asList(aCertificationChain); CertificateFactory certFactory = CertificateFactory.getInstance(X509_CERTIFICATE_TYPE); CertPath certPath = certFactory.generateCertPath(certList); byte[] certPathEncoded = certPath.getEncoded(CERTIFICATION_CHAIN_ENCODING); String base64encodedCertChain = Base64Utils.base64Encode(certPathEncoded); return base64encodedCertChain; }
Example 11
Source File: RecoveryCertPath.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@NonNull private static byte[] encodeCertPath(@NonNull CertPath certPath) throws CertificateEncodingException { Preconditions.checkNotNull(certPath); return certPath.getEncoded(CERT_PATH_ENCODING); }
Example 12
Source File: SM2CertUtil.java From gmhelper with Apache License 2.0 | 4 votes |
public static byte[] getCertificateChainBytes(CertPath certChain) throws CertificateEncodingException { return certChain.getEncoded("PKCS7"); }