본문 바로가기

Dev/Orvercome 3sec memory

Data from X509Certificate

728x90

#. X509Certificate 얻기 from a Base54 encoded String    

/**

     *      * 

     * @param encodedCertificate

     * @return

     */

    public static X509Certificate getCertificateObject(String encodedCertificate) {

    X509Certificate x509Certificate = null;

   

    try{

    // PEM encoding -> DER certificat + making InputStream

    InputStream inputStream = new ByteArrayInputStream(Base64.decode(encodedCertificate.getBytes()));

    CertificateFactory certificatFactory = CertificateFactory.getInstance("X.509");

    x509Certificate = (X509Certificate)certificatFactory.generateCertificate(inputStream);

   

    } catch(Exception e){

    System.out.println("########## ");

    e.printStackTrace();

    }

    return x509Certificate;

    }


#. PublicKey 얻기 from a Base54 encoded String

    /**

     * Extract a PublicKey from PEM Certificat

     * 

     * @param encodedCertificate

     * @return

     */

    public static PublicKey publicKeyFromCertificate(String encodedCertificate) {

    PublicKey publicKey = null;

   

    try{

    // PEM encoding -> DER certificat + making InputStream

    InputStream inputStream = new ByteArrayInputStream(Base64.decode(encodedCertificate.getBytes()));

    CertificateFactory certificatFactory = CertificateFactory.getInstance("X.509");

    X509Certificate x509Certificate = (X509Certificate)certificatFactory.generateCertificate(inputStream);

    publicKey = x509Certificate.getPublicKey();

   

    } catch(Exception e){

    System.out.println("########## ");

    e.printStackTrace();

    }

    return publicKey;

    }