Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | Github | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

第 15 章 数字证书开发

目录

15.1. Java (java.security.*)
15.1.1. 访问X.509证书
15.1.2. 创建证书
15.2. SSL Socket
15.2.1. Java Socket HTTPS
15.2.2. Java SSL Socket Client
15.2.3. Java SSL Socket Server

15.1. Java (java.security.*)

15.1.1. 访问X.509证书

Java访问X.509证书

		
/*
 * Created on 2005-7-1
 *
 * Author: neo chen <openunix@163.com>
 * Nickname: netkiller
 */
import java.io.*;
import java.security.cert.*;
import java.security.cert.CertificateFactory;

public class CertInfo {
	static String issue,after,before,subject;
	static String serialno,signalg;
	static int version;
	public void Init() throws Exception{
	CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
	FileInputStream fis=new FileInputStream("e:/Java/chen.cer");
	X509Certificate cert = (X509Certificate)certFactory.generateCertificate(fis);

	fis.close();
	issue=cert.getIssuerDN().toString();
	subject=cert.getSubjectDN().getName();
	after=cert.getNotAfter().toString();
	before=cert.getNotBefore().toString();
	version=cert.getVersion();
	serialno=cert.getSerialNumber().toString();
	signalg=cert.getSigAlgName();
	}
	public String getIssue(){
	return issue;
	}

	public String getAfter(){
	return after;
	}

	public String getBefore(){
	return before;
	}

	public String getSerial(){
	return serialno;
	}

	public String getsignalg(){
	return signalg;
	}

	public String getsubject(){
	return subject;
	}

	public String getversion(){
	return ("ver:"+version);
	}


	public static void main(String[] args) throws Exception
	{
	CertInfo c=new CertInfo();
	c.Init();
	System.out.println(c.getBefore());
	System.out.println(version);
	System.out.println(c.getversion());
	System.out.println(issue);
	System.out.println(c.getsubject());
	System.out.println(c.getsignalg());
	}
}
		
		

15.1.2. 创建证书