serialize Cert X509Certificate via Base64 encoding - Android java.lang

Android examples for java.lang:String Base64

Description

serialize Cert X509Certificate via Base64 encoding

Demo Code


//package com.java2s;

import java.security.cert.CertificateEncodingException;

import java.security.cert.X509Certificate;
import android.util.Base64;

public class Main {
    public static String serializeCert(X509Certificate cert)
            throws CertificateEncodingException {
        StringBuffer buffer = new StringBuffer();
        buffer.append("-----BEGIN CERTIFICATE-----\n");
        buffer.append(Base64.encodeToString(cert.getEncoded(),
                Base64.DEFAULT));//  w ww. j  av a 2 s.  com
        buffer.append("\n-----END CERTIFICATE-----");
        return buffer.toString();
    }
}

Related Tutorials