[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/marshal/encryption ...

Anil Saldhana anil.saldhana at jboss.com
Wed Aug 16 16:54:26 EDT 2006


  User: asaldhana
  Date: 06/08/16 16:54:26

  Modified:    src/main/org/jboss/remoting/marshal/encryption 
                        EncryptionManager.java
  Log:
  JBREM-419: Take care of feedback and padding
  
  Revision  Changes    Path
  1.2       +42 -5     JBossRemoting/src/main/org/jboss/remoting/marshal/encryption/EncryptionManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EncryptionManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/marshal/encryption/EncryptionManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- EncryptionManager.java	16 Aug 2006 19:18:30 -0000	1.1
  +++ EncryptionManager.java	16 Aug 2006 20:54:25 -0000	1.2
  @@ -28,23 +28,39 @@
   import java.util.Map;
   
   import javax.crypto.Cipher;
  +import javax.crypto.spec.IvParameterSpec;
   
   import org.jboss.logging.Logger;
   
   import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
   
  -//$Id: EncryptionManager.java,v 1.1 2006/08/16 19:18:30 asaldhana Exp $
  +//$Id: EncryptionManager.java,v 1.2 2006/08/16 20:54:25 asaldhana Exp $
   
   /**
    *  Manager that deals with the generation of the Cipher
    *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
    *  @since  Aug 11, 2006 
  - *  @version $Revision: 1.1 $
  + *  @version $Revision: 1.2 $
    */
   public class EncryptionManager
   {
      private static Logger log = Logger.getLogger(EncryptionManager.class);
      private static Map keys =  new ConcurrentHashMap(); 
  +   
  +   private static byte[] salt8 = { 
  +      (byte)0x7e, (byte)0xee, (byte)0xc8, (byte)0xc7,
  +      (byte)0x99, (byte)0x73, (byte)0x21, (byte)0x8c};
  +   
  +   private static byte[] salt16 = { 
  +      (byte)0x7e, (byte)0xee, (byte)0xc8, (byte)0xc7,
  +      (byte)0x99, (byte)0x73, (byte)0x21, (byte)0x8c,
  +      (byte)0x7e, (byte)0xee, (byte)0xc8, (byte)0xc7,
  +      (byte)0x99, (byte)0x73, (byte)0x21, (byte)0x8c};
  +   
  +   private static IvParameterSpec iv8 = new IvParameterSpec(salt8);
  +   
  +   private static IvParameterSpec iv16 = new IvParameterSpec(salt16);
  +   
      public static final String DEFAULT_CIPHER_ALGORITHM = "DES";
      
      static
  @@ -87,12 +103,13 @@
            Key key = (Key)keys.get(canonicalize(algo));
            if(key == null)
               throw new IllegalStateException("Key is null for algo="+algo);
  -         cipher.init(mode, key);
  +         initializeCipher(cipher,key,algo,mode); 
         }
         catch (Throwable e)
         {
            if(log.isTraceEnabled())
               log.trace("getCipher failed:", e);
  +         System.out.println(e);
         } 
          return cipher;
      }
  @@ -116,7 +133,7 @@
          try
         {
            cipher = Cipher.getInstance(algo);
  -         cipher.init(mode, key);
  +         initializeCipher(cipher,key,algo,mode); 
         }
         catch (Throwable e)
         {
  @@ -157,4 +174,24 @@
         } 
         return result; 
      }
  +   
  +   /**
  +    * Initialize the Cipher
  +    * @param cipher Cipher
  +    * @param key Key
  +    * @param algo Algorithm
  +    * @param mode Cipher Mode
  +    * @throws Exception
  +    */
  +   private static void initializeCipher(Cipher cipher, Key key, String algo, int mode)
  +   throws Exception
  +   {
  +      if(algo.indexOf("AES/CBC/") == 0)
  +         cipher.init(mode, key,iv16);
  +      else
  +      if(algo.indexOf("/CBC/") > 0)
  +         cipher.init(mode, key,iv8);
  +      else
  +         cipher.init(mode, key);
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list