dump X509Certificate Info - Android java.security

Android examples for java.security:Certificate

Description

dump X509Certificate Info

Demo Code


import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.Key;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.spec.PKCS8EncodedKeySpec;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.crypto.Cipher;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Base64;

public class Main{
    public static void dumpCertInfo(X509Certificate cert, LogPrinter printer) {
        Date beforedate = cert.getNotBefore();
        Date afterdate = cert.getNotAfter();
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd");
        printer.d("RSAHelper", "publickey:"
                + cert.getPublicKey().toString());
        printer.d("RSAHelper",
                "Version:" + String.valueOf(cert.getVersion()));
        printer.d("RSAHelper", "SerialNumber:"
                + cert.getSerialNumber().toString(16));
        printer.d("RSAHelper", "indate:" + dateformat.format(beforedate)
                + " to " + dateformat.format(afterdate));
        printer.d("RSAHelper", "Owner:" + cert.getSubjectDN().getName());
        printer.d("RSAHelper", "Issuer:" + cert.getIssuerDN().getName());
    }/*  www . j a  v a  2 s . c  om*/
}

Related Tutorials