KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > security > cert > extensions > KeyUsage


1
2 package com.ca.commons.security.cert.extensions;
3
4 import com.ca.commons.security.asn1.*;
5
6 /**
7  * <pre>
8  * KeyUsage ::= BIT STRING
9  * {
10  * digitalSignature (0),
11  * nonRepudiation (1),
12  * keyEncipherment (2),
13  * dataEncipherment (3),
14  * keyAgreement (4),
15  * keyCertSign (5),
16  * cRLSign (6),
17  * encipherOnly (7),
18  * decipherOnly (8) }
19  * </pre>
20  *
21  * @author vbui
22  */

23 public class KeyUsage implements V3Extension
24 {
25     String JavaDoc value = null;
26
27     public void init(ASN1Object asn1object) throws Exception JavaDoc
28     {
29         if (!asn1object.isASN1Type(ASN1Type.BIT_STRING))
30             throw new Exception JavaDoc("Wrong ASN.1 type for KeyUsage");
31
32         byte[] o = (byte[]) asn1object.getValue();
33
34         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
35
36         if ((o[1] & (byte)0x80) != 0)
37             buff.append("digitalSignature, ");
38         if ((o[1] & (byte)0x40) != 0)
39             buff.append("nonRepudiation, ");
40         if ((o[1] & (byte)0x20) != 0)
41             buff.append("keyEncipherment, ");
42         if ((o[1] & (byte)0x10) != 0)
43             buff.append("dataEncipherment, ");
44         if ((o[1] & (byte)0x08) != 0)
45             buff.append("keyAgreement, ");
46         if ((o[1] & (byte)0x04) != 0)
47             buff.append("keyCertSign, ");
48         if ((o[1] & (byte)0x02) != 0)
49             buff.append("cRLSign, ");
50         if ((o[1] & (byte)0x01) != 0)
51             buff.append("encipherOnly, ");
52         if ((o[0] & (byte)0x80) != 0) // ??
53
buff.append("decipherOnly, ");
54
55         value = buff.toString();
56         if (value.endsWith(", "))
57             value = value.substring(0, value.length() - 2);
58     }
59
60     public String JavaDoc toString()
61     {
62         return value;
63     }
64 }
65
66
Popular Tags