KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > keys > KeyUtils


1
2 /*
3  * Copyright 1999-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package com.sun.org.apache.xml.internal.security.keys;
19
20
21
22 import java.io.PrintStream JavaDoc;
23 import java.security.PublicKey JavaDoc;
24
25 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
26 import com.sun.org.apache.xml.internal.security.keys.content.KeyName;
27 import com.sun.org.apache.xml.internal.security.keys.content.KeyValue;
28 import com.sun.org.apache.xml.internal.security.keys.content.MgmtData;
29 import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
30
31
32 /**
33  * Utility class for for <CODE>com.sun.org.apache.xml.internal.security.keys</CODE> package.
34  *
35  * @author $Author: raul $
36  */

37 public class KeyUtils {
38
39    private KeyUtils() {
40       // no instantiation
41
}
42
43    /**
44     * Method prinoutKeyInfo
45     *
46     * @param ki
47     * @param os
48     * @throws XMLSecurityException
49     */

50    public static void prinoutKeyInfo(KeyInfo ki, PrintStream JavaDoc os)
51            throws XMLSecurityException {
52
53       for (int i = 0; i < ki.lengthKeyName(); i++) {
54          KeyName x = ki.itemKeyName(i);
55
56          os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
57       }
58
59       for (int i = 0; i < ki.lengthKeyValue(); i++) {
60          KeyValue x = ki.itemKeyValue(i);
61          PublicKey JavaDoc pk = x.getPublicKey();
62
63          os.println("KeyValue Nr. " + i);
64          os.println(pk);
65       }
66
67       for (int i = 0; i < ki.lengthMgmtData(); i++) {
68          MgmtData x = ki.itemMgmtData(i);
69
70          os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
71       }
72
73       for (int i = 0; i < ki.lengthX509Data(); i++) {
74          X509Data x = ki.itemX509Data(i);
75
76          os.println("X509Data(" + i + ")=\"" + (x.containsCertificate()
77                                                 ? "Certificate "
78                                                 : "") + (x
79                                                    .containsIssuerSerial()
80                                                          ? "IssuerSerial "
81                                                          : "") + "\"");
82       }
83    }
84 }
85
Popular Tags