1 17 package com.sun.org.apache.xml.internal.security.algorithms; 18 19 20 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 25 import com.sun.org.apache.xml.internal.security.Init; 26 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 27 import org.w3c.dom.Element ; 28 29 30 31 36 public class JCEMapper { 37 38 39 static java.util.logging.Logger log = 40 java.util.logging.Logger.getLogger(JCEMapper.class.getName()); 41 42 43 44 private static Map uriToJCEName = new HashMap (); 45 46 private static Map algorithmsMap = new HashMap (); 47 48 private static String providerName = null; 49 55 public static void init(Element mappingElement) throws Exception { 56 57 loadAlgorithms((Element )mappingElement.getElementsByTagName("Algorithms").item(0)); 58 } 59 60 static void loadAlgorithms( Element algorithmsEl) { 61 Element [] algorithms = XMLUtils.selectNodes(algorithmsEl.getFirstChild(),Init.CONF_NS,"Algorithm"); 62 for (int i = 0 ;i < algorithms.length ;i ++) { 63 Element el = algorithms[i]; 64 String id = el.getAttribute("URI"); 65 String jceName = el.getAttribute("JCEName"); 66 uriToJCEName.put(id, jceName); 67 algorithmsMap.put(id, new Algorithm(el)); 68 } 69 } 70 71 static Algorithm getAlgorithmMapping(String algoURI) { 72 return ((Algorithm)algorithmsMap.get(algoURI)); 73 } 74 75 82 public static String translateURItoJCEID(String AlgorithmURI) { 83 if (true) 84 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI); 85 86 String jceName = (String ) uriToJCEName.get(AlgorithmURI); 87 return jceName; 88 } 89 90 98 public static String getAlgorithmClassFromURI(String AlgorithmURI) { 99 if (true) 100 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Request for URI " + AlgorithmURI); 101 102 return ((Algorithm) algorithmsMap.get(AlgorithmURI)).algorithmClass; 103 } 104 105 111 public static int getKeyLengthFromURI(String AlgorithmURI) { 112 return Integer.parseInt(((Algorithm) algorithmsMap.get(AlgorithmURI)).keyLength); 113 } 114 115 122 public static String getJCEKeyAlgorithmFromURI(String AlgorithmURI) { 123 124 return ((Algorithm) algorithmsMap.get(AlgorithmURI)).requiredKey; 125 126 } 127 128 132 public static String getProviderId() { 133 return providerName; 134 } 135 136 140 public static void setProviderId(String provider) { 141 providerName=provider; 142 } 143 144 147 public static class Algorithm { 148 String algorithmClass; 149 String keyLength; 150 String requiredKey; 151 155 public Algorithm(Element el) { 156 algorithmClass=el.getAttribute("AlgorithmClass"); 157 keyLength=el.getAttribute("KeyLength"); 158 requiredKey=el.getAttribute("RequiredKey"); 159 } 160 } 161 } 162 | Popular Tags |