Author: lindner
Date: Mon Dec  8 14:17:20 2008
New Revision: 724513

URL: http://svn.apache.org/viewvc?rev=724513&view=rev
Log:
SHINDIG-669 | Add an encryptWithIV helper method from Rodrigo Gallardo

Modified:
    
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/crypto/Crypto.java

Modified: 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/crypto/Crypto.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/crypto/Crypto.java?rev=724513&r1=724512&r2=724513&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/crypto/Crypto.java
 (original)
+++ 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/crypto/Crypto.java
 Mon Dec  8 14:17:20 2008
@@ -154,14 +154,31 @@
   public static byte[] aes128cbcEncrypt(byte[] key, byte[] plain)
   throws GeneralSecurityException {
     Cipher cipher = Cipher.getInstance(CIPHER_TYPE);
-    Key cipherKey = new SecretKeySpec(key, CIPHER_KEY_TYPE);
     byte iv[] = getRandomBytes(cipher.getBlockSize());
+    return concat(iv, aes128cbcEncryptWithIV(key, iv, plain));
+  }
+
+  /**
+   * AES-128-CBC encryption with a given IV.
+   *
+   * @param key
+   * @param iv
+   * @param plain
+   *
+   * @return the cipher text
+   *
+   * @throws GeneralSecurityException
+   */
+  public static byte[] aes128cbcEncryptWithIV(byte[] key, byte[] iv, byte[] 
plain)
+  throws GeneralSecurityException {
+    Cipher cipher = Cipher.getInstance(CIPHER_TYPE);
+    Key cipherKey = new SecretKeySpec(key, CIPHER_KEY_TYPE);
     IvParameterSpec ivSpec = new IvParameterSpec(iv);
     cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ivSpec);
-    byte[] cipherText = cipher.doFinal(plain);
-    return concat(iv, cipherText);
+    return cipher.doFinal(plain);
   }
 
+
   /**
    * AES-128-CBC decryption.  The IV is assumed to be the first 16 bytes
    * of the cipher text.


Reply via email to