01: /*
02: * KeyValue.java
03: *
04: * Created on January 24, 2006, 4:49 PM
05: */
06:
07: /*
08: * The contents of this file are subject to the terms
09: * of the Common Development and Distribution License
10: * (the License). You may not use this file except in
11: * compliance with the License.
12: *
13: * You can obtain a copy of the license at
14: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
15: * See the License for the specific language governing
16: * permissions and limitations under the License.
17: *
18: * When distributing Covered Code, include this CDDL
19: * Header Notice in each file and include the License file
20: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
21: * If applicable, add the following below the CDDL Header,
22: * with the fields enclosed by brackets [] replaced by
23: * you own identifying information:
24: * "Portions Copyrighted [year] [name of copyright owner]"
25: *
26: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
27: */
28:
29: package com.sun.xml.ws.security.opt.crypto.dsig.keyinfo;
30:
31: import java.math.BigInteger;
32: import java.security.KeyException;
33: import java.security.KeyFactory;
34: import java.security.PublicKey;
35: import java.security.spec.DSAPublicKeySpec;
36: import java.security.spec.RSAPublicKeySpec;
37: import java.util.List;
38: import javax.xml.bind.annotation.XmlRootElement;
39:
40: /**
41: *
42: * @author Abhijit Das
43: */
44: @XmlRootElement(name="KeyValue",namespace="http://www.w3.org/2000/09/xmldsig#")
45: public class KeyValue extends
46: com.sun.xml.security.core.dsig.KeyValueType implements
47: javax.xml.crypto.dsig.keyinfo.KeyValue {
48:
49: /** Creates a new instance of KeyValue */
50: public KeyValue() {
51: }
52:
53: public PublicKey getPublicKey() throws KeyException {
54: PublicKey publicKey = null;
55: for (Object o : content) {
56: if (o instanceof DSAKeyValue) {
57: DSAKeyValue dsaKeyValue = (DSAKeyValue) o;
58:
59: DSAPublicKeySpec spec = new DSAPublicKeySpec(
60: new BigInteger(dsaKeyValue.getY()),
61: new BigInteger(dsaKeyValue.getP()),
62: new BigInteger(dsaKeyValue.getQ()),
63: new BigInteger(dsaKeyValue.getG()));
64: try {
65: KeyFactory fac = KeyFactory.getInstance("DSA");
66: return fac.generatePublic(spec);
67: } catch (Exception ex) {
68: throw new KeyException(ex);
69: }
70: } else if (o instanceof RSAKeyValue) {
71: RSAKeyValue rsaKayValue = (RSAKeyValue) o;
72:
73: RSAPublicKeySpec spec = new RSAPublicKeySpec(
74: new BigInteger(rsaKayValue.getModulus()),
75: new BigInteger(rsaKayValue.getExponent()));
76:
77: try {
78: KeyFactory fac = KeyFactory.getInstance("RSA");
79: return fac.generatePublic(spec);
80: } catch (Exception ex) {
81: throw new KeyException(ex);
82: }
83: }
84: }
85: return null;
86: }
87:
88: public boolean isFeatureSupported(String string) {
89: return false;
90: }
91:
92: public void setContent(List<Object> content) {
93: this.content = content;
94: }
95:
96: }
|