1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 * 20 */ 21 package com.sun.org.apache.xml.internal.security.keys; 22 23 24 25 import java.io.PrintStream; 26 import java.security.PublicKey; 27 28 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 29 import com.sun.org.apache.xml.internal.security.keys.content.KeyName; 30 import com.sun.org.apache.xml.internal.security.keys.content.KeyValue; 31 import com.sun.org.apache.xml.internal.security.keys.content.MgmtData; 32 import com.sun.org.apache.xml.internal.security.keys.content.X509Data; 33 34 35 /** 36 * Utility class for for <CODE>com.sun.org.apache.xml.internal.security.keys</CODE> package. 37 * 38 * @author $Author: mullan $ 39 */ 40 public class KeyUtils { 41 42 private KeyUtils() { 43 // no instantiation 44 } 45 46 /** 47 * Method prinoutKeyInfo 48 * 49 * @param ki 50 * @param os 51 * @throws XMLSecurityException 52 */ 53 public static void prinoutKeyInfo(KeyInfo ki, PrintStream os) 54 throws XMLSecurityException { 55 56 for (int i = 0; i < ki.lengthKeyName(); i++) { 57 KeyName x = ki.itemKeyName(i); 58 59 os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\""); 60 } 61 62 for (int i = 0; i < ki.lengthKeyValue(); i++) { 63 KeyValue x = ki.itemKeyValue(i); 64 PublicKey pk = x.getPublicKey(); 65 66 os.println("KeyValue Nr. " + i); 67 os.println(pk); 68 } 69 70 for (int i = 0; i < ki.lengthMgmtData(); i++) { 71 MgmtData x = ki.itemMgmtData(i); 72 73 os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\""); 74 } 75 76 for (int i = 0; i < ki.lengthX509Data(); i++) { 77 X509Data x = ki.itemX509Data(i); 78 79 os.println("X509Data(" + i + ")=\"" + (x.containsCertificate() 80 ? "Certificate " 81 : "") + (x 82 .containsIssuerSerial() 83 ? "IssuerSerial " 84 : "") + "\""); 85 } 86 } 87 }