Home  >  Core Java

Example of CodeSigner in java

By Arvind Rai, January 24, 2013
1. CodeSigner belongs to the package java.security.CodeSigner
2. CodeSigner is available from jdk1.5
3. CodeSigner contains information about code signer.
4. CodeSigner is immutable.
package com.concretepage.security;

import java.io.FileInputStream;
import java.security.CodeSigner;
import java.security.Timestamp;
import java.security.cert.CertPath;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class CodeSignerTest {
	 public static void main(String args[]) throws Exception {
	       CertificateFactory cf = CertificateFactory.getInstance("X.509");
	       List<Certificate> list = new ArrayList<Certificate>();
	     
	         FileInputStream in = new FileInputStream(args[0]);
	         Certificate c = cf.generateCertificate(in);
	         list.add(c);
	     
	       CertPath cp = cf.generateCertPath(list);
	       Timestamp ts=new Timestamp(new Date(),cp);
	       CodeSigner cs=new CodeSigner(cp,ts);
	       System.out.println(cs.getSignerCertPath());
	 }
}
While running CodeSignerTest.java, pass input as argument. Input should be a file name and that file should contain X509 encodings.
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us