1 2 package com.ca.commons.security.cert.extensions; 3 4 import com.ca.commons.security.asn1.*; 5 6 import java.util.Date ; 7 import java.text.SimpleDateFormat ; 8 9 18 public class PrivateKeyUsagePeriod implements V3Extension 19 { 20 String value = null; 21 22 public void init(ASN1Object asn1object) throws Exception 23 { 24 if (!asn1object.isASN1Type(ASN1Type.SEQUENCE)) 25 throw new Exception ("Wrong ASN.1 type for PrivateKeyUsagePeriod"); 26 27 SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMddHHmmss"); 28 SimpleDateFormat printer = new SimpleDateFormat ("MMM d, yyyy h:mm:ss a"); 29 30 String dateString = null; 31 32 for (int i = 0; i < asn1object.size(); i++) 33 { 34 ASN1Object nextComp = (ASN1Object) asn1object.getComponent(i).getValue(); 35 36 if (nextComp.isASN1Type(ASN1Type.OCTET_STRING) && i == 0) 37 { 38 String notBefore = new String ((byte[])nextComp.getValue()); 39 try 40 { 41 Date hotdate = formatter.parse(notBefore); 42 value = "Not Before: " + printer.format(hotdate); 43 } 44 catch (Exception ex) 45 { 46 ex.printStackTrace(); 47 value = "Not Before: invalid date"; 48 } 49 } 50 else if (nextComp.isASN1Type(ASN1Type.OCTET_STRING) && i == 1) 51 { 52 String notAfter = new String ((byte[])nextComp.getValue()); 53 try 54 { 55 Date hotdate = formatter.parse(notAfter); 56 value = value + "\nNot After: " + printer.format(hotdate); 57 } 58 catch (Exception ex) 59 { 60 ex.printStackTrace(); 61 value = value + "\nNot After: invalid date"; 62 } 63 } 64 } 65 } 66 67 public String toString() 68 { 69 return value; 70 } 71 } 72 73 | Popular Tags |