You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/01/31 18:08:39 UTC

svn commit: r1563179 - in /cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils: EncryptionException.java EncryptionUtils.java ModelEncryptionSupport.java

Author: sergeyb
Date: Fri Jan 31 17:08:38 2014
New Revision: 1563179

URL: http://svn.apache.org/r1563179
Log:
[CXF-5513] Some refactorings

Added:
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionException.java   (with props)
Modified:
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtils.java
    cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/ModelEncryptionSupport.java

Added: cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionException.java?rev=1563179&view=auto
==============================================================================
--- cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionException.java (added)
+++ cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionException.java Fri Jan 31 17:08:38 2014
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.oauth2.utils;
+
+public class EncryptionException extends RuntimeException {
+    private static final long serialVersionUID = -8231433265954055715L;
+
+    public EncryptionException(Throwable t) {
+        super(t);
+    }
+}

Propchange: cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtils.java?rev=1563179&r1=1563178&r2=1563179&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtils.java (original)
+++ cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtils.java Fri Jan 31 17:08:38 2014
@@ -32,7 +32,6 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.cxf.common.util.CompressionUtils;
 import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
 
 
 /**
@@ -42,137 +41,128 @@ public final class EncryptionUtils {
     private EncryptionUtils() {
     }
     
-    public static String encodeSecretKey(SecretKey key) throws Exception {
-        try {
-            return encodeBytes(key.getEncoded());
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+    public static String encodeSecretKey(SecretKey key) throws EncryptionException {
+        return encodeBytes(key.getEncoded());
     }
     
-    public static String encryptSecretKey(SecretKey secretKey, PublicKey publicKey) throws Exception {
+    public static String encryptSecretKey(SecretKey secretKey, PublicKey publicKey) 
+        throws EncryptionException {
         SecretKeyProperties props = new SecretKeyProperties();
         props.setCompressionSupported(false);
         return encryptSecretKey(secretKey, publicKey, props);
     }
     
-    public static String encryptSecretKey(SecretKey secretKey, 
-                                          PublicKey publicKey,
-                                          SecretKeyProperties props) throws Exception {
-        try {
-            byte[] encryptedBytes = encryptBytes(secretKey.getEncoded(), 
-                                                 publicKey,
-                                                 props);
-            return encodeBytes(encryptedBytes);
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+    public static String encryptSecretKey(SecretKey secretKey, PublicKey publicKey,
+        SecretKeyProperties props) throws EncryptionException {
+        byte[] encryptedBytes = encryptBytes(secretKey.getEncoded(), 
+                                             publicKey,
+                                             props);
+        return encodeBytes(encryptedBytes);
     }
     
     public static SecretKey getSecretKey() throws Exception {
         return getSecretKey("AES");
     }
     
-    public static SecretKey getSecretKey(String symEncAlgo) throws Exception {
-        KeyGenerator keyGen = KeyGenerator.getInstance(symEncAlgo);
-        return keyGen.generateKey();
+    public static SecretKey getSecretKey(String symEncAlgo) throws EncryptionException {
+        return getSecretKey(new SecretKeyProperties(symEncAlgo));
     }
     
-    public static SecretKey getSecretKey(SecretKeyProperties props) throws Exception {
-        KeyGenerator keyGen = KeyGenerator.getInstance(props.getKeyAlgo());
-        AlgorithmParameterSpec algoSpec = props.getAlgoSpec();
-        SecureRandom random = props.getSecureRandom();
-        if (algoSpec != null) {
-            if (random != null) {
-                keyGen.init(algoSpec, random);
-            } else {
-                keyGen.init(algoSpec);
-            }
-        } else {
-            if (random != null) {
-                keyGen.init(props.getKeySize(), random);
+    public static SecretKey getSecretKey(SecretKeyProperties props) throws EncryptionException {
+        try {
+            KeyGenerator keyGen = KeyGenerator.getInstance(props.getKeyAlgo());
+            AlgorithmParameterSpec algoSpec = props.getAlgoSpec();
+            SecureRandom random = props.getSecureRandom();
+            if (algoSpec != null) {
+                if (random != null) {
+                    keyGen.init(algoSpec, random);
+                } else {
+                    keyGen.init(algoSpec);
+                }
             } else {
-                keyGen.init(props.getKeySize());
+                if (random != null) {
+                    keyGen.init(props.getKeySize(), random);
+                } else {
+                    keyGen.init(props.getKeySize());
+                }
             }
+            
+            return keyGen.generateKey();
+        } catch (Exception ex) {
+            throw new EncryptionException(ex);
         }
-        
-        return keyGen.generateKey();
     }
     
-    public static String decryptSequence(String encodedToken, 
-                                         String encodedSecretKey) {
+    public static String decryptSequence(String encodedToken, String encodedSecretKey)
+        throws EncryptionException {
         return decryptSequence(encodedToken, encodedSecretKey, new SecretKeyProperties("AES"));
     }
     
-    public static String decryptSequence(String encodedData, 
-                                         String encodedSecretKey, 
-                                         SecretKeyProperties props) {
-        try {
-            SecretKey key = decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
-            return decryptSequence(encodedData, key, props);
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+    public static String decryptSequence(String encodedData, String encodedSecretKey, 
+        SecretKeyProperties props) throws EncryptionException {
+        SecretKey key = decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
+        return decryptSequence(encodedData, key, props);
     }
     
-    public static String decryptSequence(String encodedData, Key secretKey) {
+    public static String decryptSequence(String encodedData, Key secretKey) throws EncryptionException {
         return decryptSequence(encodedData, secretKey, null);
     }
     
-    public static String decryptSequence(String encodedData, 
-                                              Key secretKey,
-                                              SecretKeyProperties props) {
+    public static String decryptSequence(String encodedData, Key secretKey,
+        SecretKeyProperties props) throws EncryptionException {
+        byte[] encryptedBytes = decodeSequence(encodedData);
+        byte[] bytes = decryptBytes(encryptedBytes, secretKey, props);
         try {
-            byte[] encryptedBytes = decodeSequence(encodedData);
-            byte[] bytes = decryptBytes(encryptedBytes, secretKey, props);
             return new String(bytes, "UTF-8");
         } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
+            throw new EncryptionException(ex);
         }
     }
     
-    public static String encryptSequence(String sequence, Key secretKey) {
+    public static String encryptSequence(String sequence, Key secretKey) throws EncryptionException {
         return encryptSequence(sequence, secretKey, null);
     }
     
     public static String encryptSequence(String sequence, Key secretKey,
-                                         SecretKeyProperties keyProps) {
+        SecretKeyProperties keyProps) throws EncryptionException {
         try {
             byte[] bytes = encryptBytes(sequence.getBytes("UTF-8"), secretKey, keyProps);
             return encodeBytes(bytes);
         } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
+            throw new EncryptionException(ex);
         }
     }
     
-    public static String encodeBytes(byte[] bytes) throws Exception {
+    public static String encodeBytes(byte[] bytes) throws EncryptionException {
         try {
             return Base64UrlUtility.encode(bytes);
         } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
+            throw new EncryptionException(ex);
         }
     }
     
-    public static byte[] encryptBytes(byte[] bytes, Key secretKey) {
+    public static byte[] encryptBytes(byte[] bytes, Key secretKey) throws EncryptionException {
         return encryptBytes(bytes, secretKey, null);
     }
     
-    public static byte[] encryptBytes(byte[] bytes, Key secretKey, SecretKeyProperties keyProps) {
+    public static byte[] encryptBytes(byte[] bytes, Key secretKey,
+        SecretKeyProperties keyProps) throws EncryptionException {
         return processBytes(bytes, secretKey, keyProps, Cipher.ENCRYPT_MODE);
     }
     
-    public static byte[] decryptBytes(byte[] bytes, Key secretKey) {
+    public static byte[] decryptBytes(byte[] bytes, Key secretKey) throws EncryptionException {
         return decryptBytes(bytes, secretKey, null);
     }
     
-    public static byte[] decryptBytes(byte[] bytes, Key secretKey, SecretKeyProperties keyProps) {
+    public static byte[] decryptBytes(byte[] bytes, Key secretKey, 
+        SecretKeyProperties keyProps) throws EncryptionException {
         return processBytes(bytes, secretKey, keyProps, Cipher.DECRYPT_MODE);
     }
     
     private static byte[] processBytes(byte[] bytes, 
                                       Key secretKey, 
                                       SecretKeyProperties keyProps, 
-                                      int mode) {
+                                      int mode)  throws EncryptionException {
         boolean compressionSupported = keyProps != null && keyProps.isCompressionSupported();
         if (compressionSupported && mode == Cipher.ENCRYPT_MODE) {
             bytes = CompressionUtils.compress(bytes, false);
@@ -213,7 +203,7 @@ public final class EncryptionUtils {
             }
             return result;
         } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
+            throw new EncryptionException(ex);
         }
     }
     
@@ -224,20 +214,18 @@ public final class EncryptionUtils {
         return result;
     }
     
-    public static SecretKey decodeSecretKey(String encodedSecretKey) {
+    public static SecretKey decodeSecretKey(String encodedSecretKey) throws EncryptionException {
         return decodeSecretKey(encodedSecretKey, "AES");
     }
     
-    public static SecretKey decodeSecretKey(String encodedSecretKey, String algo) {
-        try {
-            byte[] secretKeyBytes = decodeSequence(encodedSecretKey);
-            return new SecretKeySpec(secretKeyBytes, algo);
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+    public static SecretKey decodeSecretKey(String encodedSecretKey, String algo) 
+        throws EncryptionException {
+        byte[] secretKeyBytes = decodeSequence(encodedSecretKey);
+        return recreateSecretKey(secretKeyBytes, algo);
     }
     
-    public static SecretKey decryptSecretKey(String encodedEncryptedSecretKey, PrivateKey privateKey) {
+    public static SecretKey decryptSecretKey(String encodedEncryptedSecretKey, PrivateKey privateKey)
+        throws EncryptionException {
         SecretKeyProperties props = new SecretKeyProperties();
         props.setCompressionSupported(false);
         return decryptSecretKey(encodedEncryptedSecretKey, props, privateKey);
@@ -245,21 +233,21 @@ public final class EncryptionUtils {
     
     public static SecretKey decryptSecretKey(String encodedEncryptedSecretKey, 
                                              SecretKeyProperties props,
-                                             PrivateKey privateKey) {
-        try {
-            byte[] encryptedBytes = decodeSequence(encodedEncryptedSecretKey);
-            byte[] descryptedBytes = decryptBytes(encryptedBytes, privateKey, props);
-            return new SecretKeySpec(descryptedBytes, props.getKeyAlgo());
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+                                             PrivateKey privateKey) throws EncryptionException {
+        byte[] encryptedBytes = decodeSequence(encodedEncryptedSecretKey);
+        byte[] descryptedBytes = decryptBytes(encryptedBytes, privateKey, props);
+        return recreateSecretKey(descryptedBytes, props.getKeyAlgo());
+    }
+    
+    public static SecretKey recreateSecretKey(byte[] bytes, String algo) {
+        return new SecretKeySpec(bytes, algo);
     }
     
-    public static byte[] decodeSequence(String encodedSequence) {
+    public static byte[] decodeSequence(String encodedSequence) throws EncryptionException {
         try {
             return Base64UrlUtility.decode(encodedSequence);
         } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
+            throw new EncryptionException(ex);
         }
     }
     

Modified: cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/ModelEncryptionSupport.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/ModelEncryptionSupport.java?rev=1563179&r1=1563178&r2=1563179&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/ModelEncryptionSupport.java (original)
+++ cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/ModelEncryptionSupport.java Fri Jan 31 17:08:38 2014
@@ -35,7 +35,6 @@ import org.apache.cxf.rs.security.oauth2
 import org.apache.cxf.rs.security.oauth2.common.UserSubject;
 import org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant;
 import org.apache.cxf.rs.security.oauth2.provider.OAuthDataProvider;
-import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
 import org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken;
 
 
@@ -47,177 +46,163 @@ public final class ModelEncryptionSuppor
     private ModelEncryptionSupport() {
     }
     
-    public static String encryptClient(Client client, Key secretKey) {
+    public static String encryptClient(Client client, Key secretKey) throws EncryptionException {
         return encryptClient(client, secretKey, null);
     }
      
     public static String encryptClient(Client client, Key secretKey,
-                                       SecretKeyProperties props) {
+                                       SecretKeyProperties props) throws EncryptionException {
         String tokenSequence = tokenizeClient(client);
         return EncryptionUtils.encryptSequence(tokenSequence, secretKey, props);
     }
     
-    public static String encryptAccessToken(ServerAccessToken token, Key secretKey) {
+    public static String encryptAccessToken(ServerAccessToken token, Key secretKey) throws EncryptionException {
         return encryptAccessToken(token, secretKey, null);
     }
     
     public static String encryptAccessToken(ServerAccessToken token, Key secretKey,
-                                            SecretKeyProperties props) {
+                                            SecretKeyProperties props) throws EncryptionException {
         String tokenSequence = tokenizeServerToken(token);
         return EncryptionUtils.encryptSequence(tokenSequence, secretKey, props);
     }
     
-    public static String encryptRefreshToken(RefreshToken token, Key secretKey) {
+    public static String encryptRefreshToken(RefreshToken token, Key secretKey) throws EncryptionException {
         return encryptRefreshToken(token, secretKey, null);
     }
     
     public static String encryptRefreshToken(RefreshToken token, Key secretKey,
-                                             SecretKeyProperties props) {
+                                             SecretKeyProperties props) throws EncryptionException {
         String tokenSequence = tokenizeRefreshToken(token);
         
         return EncryptionUtils.encryptSequence(tokenSequence, secretKey, props);
     }
     
-    public static String encryptCodeGrant(ServerAuthorizationCodeGrant grant, Key secretKey) {
+    public static String encryptCodeGrant(ServerAuthorizationCodeGrant grant, Key secretKey) 
+        throws EncryptionException {
         return encryptCodeGrant(grant, secretKey, null);
     }
     
     public static String encryptCodeGrant(ServerAuthorizationCodeGrant grant, Key secretKey,
-                                             SecretKeyProperties props) {
+                                          SecretKeyProperties props) throws EncryptionException {
         String tokenSequence = tokenizeCodeGrant(grant);
         
         return EncryptionUtils.encryptSequence(tokenSequence, secretKey, props);
     }
     
-    public static Client decryptClient(String encodedSequence, String encodedSecretKey) {
+    public static Client decryptClient(String encodedSequence, String encodedSecretKey) 
+        throws EncryptionException {
         return decryptClient(encodedSequence, encodedSecretKey, new SecretKeyProperties("AES"));
     }
     
     public static Client decryptClient(String encodedSequence, String encodedSecretKey,
-                                       SecretKeyProperties props) {
+                                       SecretKeyProperties props) throws EncryptionException {
         SecretKey key = EncryptionUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
         return decryptClient(encodedSequence, key, props);
     }
     
-    public static Client decryptClient(String encodedSequence, Key secretKey) {
+    public static Client decryptClient(String encodedSequence, Key secretKey) throws EncryptionException {
         return decryptClient(encodedSequence, secretKey, null);
     }
     
     public static Client decryptClient(String encodedData, Key secretKey, 
-                                       SecretKeyProperties props) {
-        try {
-            String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, secretKey, props);
-            return recreateClient(decryptedSequence);
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+                                       SecretKeyProperties props) throws EncryptionException {
+        String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, secretKey, props);
+        return recreateClient(decryptedSequence);
     }
     
     public static ServerAccessToken decryptAccessToken(OAuthDataProvider provider,
                                                  String encodedToken, 
-                                                 String encodedSecretKey) {
+                                                 String encodedSecretKey) throws EncryptionException {
         return decryptAccessToken(provider, encodedToken, encodedSecretKey, new SecretKeyProperties("AES"));
     }
     
     public static ServerAccessToken decryptAccessToken(OAuthDataProvider provider,
                                                  String encodedToken, 
                                                  String encodedSecretKey,
-                                                 SecretKeyProperties props) {
+                                                 SecretKeyProperties props) throws EncryptionException {
         SecretKey key = EncryptionUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
         return decryptAccessToken(provider, encodedToken, key, props);
     }
     
     public static ServerAccessToken decryptAccessToken(OAuthDataProvider provider,
                                                  String encodedToken, 
-                                                 Key secretKey) {
+                                                 Key secretKey) throws EncryptionException {
         return decryptAccessToken(provider, encodedToken, secretKey, null);
     }
     
     public static ServerAccessToken decryptAccessToken(OAuthDataProvider provider,
                                                  String encodedData, 
                                                  Key secretKey, 
-                                                 SecretKeyProperties props) {
-        try {
-            String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, secretKey, props);
-            return recreateAccessToken(provider, encodedData, decryptedSequence);
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+                                                 SecretKeyProperties props) throws EncryptionException {
+        String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, secretKey, props);
+        return recreateAccessToken(provider, encodedData, decryptedSequence);
     }
     
     public static RefreshToken decryptRefreshToken(OAuthDataProvider provider,
                                                    String encodedToken, 
-                                                   String encodedSecretKey) {
+                                                   String encodedSecretKey) throws EncryptionException {
         return decryptRefreshToken(provider, encodedToken, encodedSecretKey, new SecretKeyProperties("AES"));
     }
     
     public static RefreshToken decryptRefreshToken(OAuthDataProvider provider,
                                                   String encodedToken, 
                                                   String encodedSecretKey,
-                                                  SecretKeyProperties props) {
+                                                  SecretKeyProperties props) throws EncryptionException {
         SecretKey key = EncryptionUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
         return decryptRefreshToken(provider, encodedToken, key, props);
     }
     
     public static RefreshToken decryptRefreshToken(OAuthDataProvider provider,
                                                    String encodedToken, 
-                                                   Key key) {
+                                                   Key key) throws EncryptionException {
         return decryptRefreshToken(provider, encodedToken, key, null);
     }
     
     public static RefreshToken decryptRefreshToken(OAuthDataProvider provider,
                                                    String encodedData, 
                                                    Key key, 
-                                                   SecretKeyProperties props) {
-        try {
-            String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, key, props);
-            return recreateRefreshToken(provider, encodedData, decryptedSequence);
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+                                                   SecretKeyProperties props) throws EncryptionException {
+        String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, key, props);
+        return recreateRefreshToken(provider, encodedData, decryptedSequence);
     }
     
     public static ServerAuthorizationCodeGrant decryptCodeGrant(OAuthDataProvider provider,
                                                    String encodedToken, 
-                                                   String encodedSecretKey) {
+                                                   String encodedSecretKey) throws EncryptionException {
         return decryptCodeGrant(provider, encodedToken, encodedSecretKey, new SecretKeyProperties("AES"));
     }
     
     public static ServerAuthorizationCodeGrant decryptCodeGrant(OAuthDataProvider provider,
                                                   String encodedToken, 
                                                   String encodedSecretKey,
-                                                  SecretKeyProperties props) {
+                                                  SecretKeyProperties props) throws EncryptionException {
         SecretKey key = EncryptionUtils.decodeSecretKey(encodedSecretKey, props.getKeyAlgo());
         return decryptCodeGrant(provider, encodedToken, key, props);
     }
     
     public static ServerAuthorizationCodeGrant decryptCodeGrant(OAuthDataProvider provider,
                                                    String encodedToken, 
-                                                   Key key) {
+                                                   Key key) throws EncryptionException {
         return decryptCodeGrant(provider, encodedToken, key, null);
     }
     
     public static ServerAuthorizationCodeGrant decryptCodeGrant(OAuthDataProvider provider,
                                                    String encodedData, 
                                                    Key key, 
-                                                   SecretKeyProperties props) {
-        try {
-            String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, key, props);
-            return recreateCodeGrant(provider, decryptedSequence);
-        } catch (Exception ex) {
-            throw new OAuthServiceException(ex);
-        }
+                                                   SecretKeyProperties props) throws EncryptionException {
+        String decryptedSequence = EncryptionUtils.decryptSequence(encodedData, key, props);
+        return recreateCodeGrant(provider, decryptedSequence);
     }
     
     public static ServerAccessToken recreateAccessToken(OAuthDataProvider provider,
                                                   String newTokenKey,
-                                                  String decryptedSequence) {
+                                                  String decryptedSequence) throws EncryptionException {
         return recreateAccessToken(provider, newTokenKey, getParts(decryptedSequence));
     }
     
     public static RefreshToken recreateRefreshToken(OAuthDataProvider provider,
                                                     String newTokenKey,
-                                                    String decryptedSequence) {
+                                                    String decryptedSequence) throws EncryptionException {
         String[] parts = getParts(decryptedSequence);
         ServerAccessToken token = recreateAccessToken(provider, newTokenKey, parts);
         return new RefreshToken(token, 
@@ -226,11 +211,11 @@ public final class ModelEncryptionSuppor
     }
     
     public static ServerAuthorizationCodeGrant recreateCodeGrant(OAuthDataProvider provider,
-                                                                 String decryptedSequence) {
+        String decryptedSequence) throws EncryptionException {
         return recreateCodeGrantInternal(provider, decryptedSequence);
     }
     
-    public static Client recreateClient(String sequence) {
+    public static Client recreateClient(String sequence) throws EncryptionException {
         return recreateClientInternal(sequence);
     }