1 17 package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations; 18 19 import java.security.Key ; 20 import java.security.PublicKey ; 21 import java.security.cert.X509Certificate ; 22 23 import javax.crypto.SecretKey; 24 25 import com.sun.org.apache.xml.internal.security.encryption.EncryptedKey; 26 import com.sun.org.apache.xml.internal.security.encryption.XMLCipher; 27 import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi; 28 import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver; 29 import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants; 30 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 31 import org.w3c.dom.Element ; 32 33 34 46 47 public class EncryptedKeyResolver extends KeyResolverSpi { 48 49 50 static java.util.logging.Logger log = 51 java.util.logging.Logger.getLogger( 52 RSAKeyValueResolver.class.getName()); 53 54 55 Key _key; 56 Key _kek; 57 String _algorithm; 58 59 64 public EncryptedKeyResolver(String algorithm) { 65 _key = null; 66 _kek = null; 67 _algorithm=algorithm; 68 } 69 70 75 76 public EncryptedKeyResolver(String algorithm, Key kek) { 77 _key = null; 78 _algorithm = algorithm; 79 _kek = kek; 80 81 } 82 83 92 93 public boolean engineCanResolve(Element element, String BaseURI, 94 StorageResolver storage) { 95 if (true) 96 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "EncryptedKeyResolver - Can I resolve " + element.getTagName()); 97 98 if (element == null) { 99 return false; 100 } 101 102 boolean isEncryptedKey = XMLUtils.elementIsInEncryptionSpace(element, 103 EncryptionConstants._TAG_ENCRYPTEDKEY); 104 105 if (isEncryptedKey) { 106 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Passed an Encrypted Key"); 107 try { 108 XMLCipher cipher = XMLCipher.getInstance(); 109 cipher.init(XMLCipher.UNWRAP_MODE, _kek); 110 EncryptedKey ek = cipher.loadEncryptedKey(element); 111 _key = cipher.decryptKey(ek, _algorithm); 112 } 113 catch (Exception e) {} 114 } 115 116 return (_key != null); 117 } 118 119 120 public PublicKey engineResolvePublicKey( 121 Element element, String BaseURI, StorageResolver storage) { 122 123 return null; 124 } 125 126 127 public X509Certificate engineResolveX509Certificate( 128 Element element, String BaseURI, StorageResolver storage) { 129 return null; 130 } 131 132 133 public javax.crypto.SecretKey engineResolveSecretKey( 134 Element element, String BaseURI, StorageResolver storage) { 135 return (SecretKey) _key; 136 } 137 } 138 | Popular Tags |