[java-opensaml COMMIT] in /trunk/opensaml-security-api/src/main/java/org/opensaml/security/crypto: JCAConstants.java ...

noreply at shibboleth.net noreply at shibboleth.net
Fri Apr 4 16:07:10 EDT 2014


Author: putmanb
Date: Fri Apr  4 16:07:10 2014
New Revision: 3763

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3763&view=rev
Log:
OSJ-46: Constants for JCA key algorithms.
Update KeySupport class to use the new constants.

Added:
    trunk/opensaml-security-api/src/main/java/org/opensaml/security/crypto/JCAConstants.java   (with props)
Modified:
    trunk/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java

Modified: trunk/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java?rev=3763&r1=3762&r2=3763&view=diff
==============================================================================
--- trunk/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java (original)
+++ trunk/opensaml-security-api/src/main/java/org/opensaml/security/crypto/KeySupport.java Fri Apr  4 16:07:10 2014
@@ -87,7 +87,7 @@
         log.debug("Attempting to determine length of Key with algorithm '{}' and encoding format '{}'", 
                 key.getAlgorithm(), key.getFormat());
         // TODO investigate if exists, and can/how to support, non-RAW format symmetric keys
-        if (key instanceof SecretKey && "RAW".equals(key.getFormat())) {
+        if (key instanceof SecretKey && JCAConstants.KEY_FORMAT_RAW.equals(key.getFormat())) {
             return key.getEncoded().length * 8;
         } else if (key instanceof RSAKey) {
             return ((RSAKey) key).getModulus().bitLength();
@@ -132,15 +132,15 @@
         
         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(key);
         try {
-            return buildKey(keySpec, "RSA");
+            return buildKey(keySpec, JCAConstants.KEY_ALGO_RSA);
         } catch (KeyException ex) {
         }
         try {
-            return buildKey(keySpec, "DSA");
+            return buildKey(keySpec, JCAConstants.KEY_ALGO_DSA);
         } catch (KeyException ex) {
         }
         try {
-            return buildKey(keySpec, "EC");
+            return buildKey(keySpec, JCAConstants.KEY_ALGO_EC);
         } catch (KeyException ex) {
         }
         throw new KeyException("Unsupported key type.");
@@ -215,7 +215,7 @@
             DSAPublicKeySpec pubKeySpec = new DSAPublicKeySpec(y, keyParams.getP(), keyParams.getQ(), keyParams.getG());
 
             try {
-                factory = KeyFactory.getInstance("DSA");
+                factory = KeyFactory.getInstance(JCAConstants.KEY_ALGO_DSA);
                 return factory.generatePublic(pubKeySpec);
             } catch (GeneralSecurityException e) {
                 throw new KeyException("Unable to derive public key from DSA private key", e);
@@ -225,7 +225,7 @@
             RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(rsaKey.getModulus(), rsaKey.getPublicExponent());
 
             try {
-                factory = KeyFactory.getInstance("RSA");
+                factory = KeyFactory.getInstance(JCAConstants.KEY_ALGO_RSA);
                 return factory.generatePublic(pubKeySpec);
             } catch (GeneralSecurityException e) {
                 throw new KeyException("Unable to derive public key from RSA private key", e);
@@ -245,7 +245,7 @@
     @Nonnull public static DSAPublicKey buildJavaDSAPublicKey(@Nonnull final String base64EncodedKey)
             throws KeyException {
         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64Support.decode(base64EncodedKey));
-        return (DSAPublicKey) buildKey(keySpec, "DSA");
+        return (DSAPublicKey) buildKey(keySpec, JCAConstants.KEY_ALGO_DSA);
     }
 
     /**
@@ -258,7 +258,7 @@
     @Nonnull public static RSAPublicKey buildJavaRSAPublicKey(@Nonnull final String base64EncodedKey)
             throws KeyException {
         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64Support.decode(base64EncodedKey));
-        return (RSAPublicKey) buildKey(keySpec, "RSA");
+        return (RSAPublicKey) buildKey(keySpec, JCAConstants.KEY_ALGO_RSA);
     }
 
     /**
@@ -271,7 +271,7 @@
     @Nonnull public static ECPublicKey buildJavaECPublicKey(@Nonnull final String base64EncodedKey)
             throws KeyException {
         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64Support.decode(base64EncodedKey));
-        return (ECPublicKey) buildKey(keySpec, "EC");
+        return (ECPublicKey) buildKey(keySpec, JCAConstants.KEY_ALGO_EC);
     }
 
     /**
@@ -340,7 +340,7 @@
      * 
      * @return the generated {@link PublicKey}
      * 
-     * @throws KeyException thrown if the key algorithm is not supported by the JCE or the key spec does not contain
+     * @throws KeyException thrown if the key algorithm is not supported by the JCA or the key spec does not contain
      *             valid information
      */
     @Nonnull public static PublicKey buildKey(@Nullable final KeySpec keySpec, @Nonnull final String keyAlgorithm)
@@ -351,7 +351,7 @@
             KeyFactory keyFactory = KeyFactory.getInstance(keyAlgorithm);

[... 21 lines stripped ...]


More information about the commits mailing list