1 17 package com.sun.org.apache.xml.internal.security.keys.content.keyvalues; 18 19 20 21 import java.math.BigInteger ; 22 import java.security.Key ; 23 import java.security.KeyFactory ; 24 import java.security.NoSuchAlgorithmException ; 25 import java.security.PublicKey ; 26 import java.security.interfaces.RSAPublicKey ; 27 import java.security.spec.InvalidKeySpecException ; 28 import java.security.spec.RSAPublicKeySpec ; 29 30 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 31 import com.sun.org.apache.xml.internal.security.utils.Constants; 32 import com.sun.org.apache.xml.internal.security.utils.I18n; 33 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; 34 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.Element ; 37 38 39 43 public class RSAKeyValue extends SignatureElementProxy 44 implements KeyValueContent { 45 46 47 static java.util.logging.Logger log = 48 java.util.logging.Logger.getLogger( 49 RSAKeyValue.class.getName()); 50 51 58 public RSAKeyValue(Element element, String BaseURI) 59 throws XMLSecurityException { 60 super(element, BaseURI); 61 } 62 63 70 public RSAKeyValue(Document doc, BigInteger modulus, BigInteger exponent) { 71 72 super(doc); 73 74 XMLUtils.addReturnToElement(this._constructionElement); 75 this.addBigIntegerElement(modulus, Constants._TAG_MODULUS); 76 this.addBigIntegerElement(exponent, Constants._TAG_EXPONENT); 77 } 78 79 86 public RSAKeyValue(Document doc, Key key) throws IllegalArgumentException { 87 88 super(doc); 89 90 XMLUtils.addReturnToElement(this._constructionElement); 91 92 if (key instanceof java.security.interfaces.RSAPublicKey ) { 93 this.addBigIntegerElement(((RSAPublicKey ) key).getModulus(), 94 Constants._TAG_MODULUS); 95 this.addBigIntegerElement(((RSAPublicKey ) key).getPublicExponent(), 96 Constants._TAG_EXPONENT); 97 } else { 98 Object exArgs[] = { Constants._TAG_RSAKEYVALUE, 99 key.getClass().getName() }; 100 101 throw new IllegalArgumentException (I18n 102 .translate("KeyValue.IllegalArgument", exArgs)); 103 } 104 } 105 106 107 public PublicKey getPublicKey() throws XMLSecurityException { 108 109 try { 110 KeyFactory rsaFactory = KeyFactory.getInstance("RSA"); 111 112 RSAPublicKeySpec rsaKeyspec = 114 new RSAPublicKeySpec (this 115 .getBigIntegerFromChildElement(Constants._TAG_MODULUS, Constants 116 .SignatureSpecNS), this 117 .getBigIntegerFromChildElement(Constants 118 ._TAG_EXPONENT, Constants.SignatureSpecNS)); 119 PublicKey pk = rsaFactory.generatePublic(rsaKeyspec); 120 121 return pk; 122 } catch (NoSuchAlgorithmException ex) { 123 throw new XMLSecurityException("empty", ex); 124 } catch (InvalidKeySpecException ex) { 125 throw new XMLSecurityException("empty", ex); 126 } 127 } 128 129 130 public String getBaseLocalName() { 131 return Constants._TAG_RSAKEYVALUE; 132 } 133 } 134 | Popular Tags |