Author: anil.saldhana(a)jboss.com
Date: 2009-05-22 18:32:21 -0400 (Fri, 22 May 2009)
New Revision: 507
Added:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/XMLEncryptionUtil.java
Log:
new version of xmlenc util
Added:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/XMLEncryptionUtil.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/XMLEncryptionUtil.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/XMLEncryptionUtil.java 2009-05-22
22:32:21 UTC (rev 507)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.core.util;
+
+import java.util.HashMap;
+
+import org.apache.xml.security.encryption.XMLCipher;
+
+/**
+ * Utility for XML Encryption
+ * @author Anil.Saldhana(a)redhat.com
+ * @since May 4, 2009
+ */
+public class XMLEncryptionUtil
+{
+ private static HashMap <String, EncryptionAlgorithm> algorithms
+ = new HashMap<String, EncryptionAlgorithm>(4);
+
+ private static class EncryptionAlgorithm
+ {
+ EncryptionAlgorithm(String jceName, String xmlSecName, int size)
+ {
+ this.jceName = jceName;
+ this.xmlSecName = xmlSecName;
+ this.size = size;
+ }
+
+ public String jceName;
+ public String xmlSecName;
+ public int size;
+ }
+
+ static
+ {
+ algorithms.put("aes-128", new EncryptionAlgorithm("AES",
XMLCipher.AES_128, 128));
+ algorithms.put("aes-192", new EncryptionAlgorithm("AES",
XMLCipher.AES_192, 192));
+ algorithms.put("aes-256", new EncryptionAlgorithm("AES",
XMLCipher.AES_256, 256));
+ algorithms.put("aes", new EncryptionAlgorithm("AES",
XMLCipher.AES_256, 256));
+
+ algorithms.put("tripledes", new
EncryptionAlgorithm("TripleDes",
+ XMLCipher.TRIPLEDES, 168));
+ }
+
+ /**
+ * Given the JCE algorithm, get the XML Encryption URL
+ * @param certAlgo
+ * @return
+ */
+ public static String getEncryptionURL(String certAlgo)
+ {
+ EncryptionAlgorithm ea = algorithms.get(certAlgo);
+ if(ea == null)
+ throw new RuntimeException("Unknown jce algorithm:" + certAlgo);
+ return ea.xmlSecName;
+ }
+
+ /**
+ * Given the JCE algorithm, get the XML Encryption KeySize
+ * @param certAlgo
+ * @return
+ */
+ public static int getEncryptionKeySize(String certAlgo)
+ {
+ EncryptionAlgorithm ea = algorithms.get(certAlgo);
+ if(ea == null)
+ throw new RuntimeException("Unknown jce algorithm:" + certAlgo);
+ return ea.size;
+ }
+}
\ No newline at end of file