cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1584628 - in /cayenne/main/trunk/cayenne-crypto/src: main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtils.java test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtilsTest.java
Date Fri, 04 Apr 2014 12:03:42 GMT
Author: aadamchik
Date: Fri Apr  4 12:03:42 2014
New Revision: 1584628

URL: http://svn.apache.org/r1584628
Log:
CAY-1916 cayenne-crypto module that enables data encryption for certain model attributes

integration testing and fixes

Modified:
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtils.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtilsTest.java

Modified: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java?rev=1584628&r1=1584627&r2=1584628&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
Fri Apr  4 12:03:42 2014
@@ -36,6 +36,7 @@ import org.apache.cayenne.crypto.transfo
 import org.apache.cayenne.crypto.transformer.TransformerFactory;
 import org.apache.cayenne.crypto.transformer.bytes.BytesTransformerFactory;
 import org.apache.cayenne.crypto.transformer.bytes.DefaultBytesTransformerFactory;
+import org.apache.cayenne.crypto.transformer.value.JceValueTransformerFactory;
 import org.apache.cayenne.crypto.transformer.value.ValueTransformerFactory;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.MapBuilder;
@@ -85,6 +86,8 @@ public class CryptoModuleBuilder {
         this.keySourceType = JceksKeySource.class;
 
         this.columnMapperPattern = "^CRYPTO_";
+        
+        this.valueTransformerFactoryType = JceValueTransformerFactory.class;
     }
 
     public CryptoModuleBuilder cipherAlgorithm(String algorithm) {

Modified: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtils.java?rev=1584628&r1=1584627&r2=1584628&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtils.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtils.java
Fri Apr  4 12:03:42 2014
@@ -19,10 +19,19 @@
 package org.apache.cayenne.crypto.unit;
 
 import java.math.BigInteger;
+import java.security.Key;
 import java.util.Arrays;
 
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.crypto.key.KeySource;
+
 public class CryptoUnitUtils {
 
+    private static final int DEFAULT_BLOCK_SIZE = 16;
+
     public static byte[] hexToBytes(String hexString) {
         byte[] bytes = new BigInteger(hexString, 16).toByteArray();
 
@@ -34,4 +43,26 @@ public class CryptoUnitUtils {
         }
     }
 
+    public static byte[] decrypt_AES_CBC(byte[] source, ServerRuntime runtime) {
+
+        byte[] keyNameBytes = Arrays.copyOfRange(source, 0, DEFAULT_BLOCK_SIZE);
+        byte[] ivBytes = Arrays.copyOfRange(source, DEFAULT_BLOCK_SIZE, DEFAULT_BLOCK_SIZE
* 2);
+        byte[] cipherText = Arrays.copyOfRange(source, DEFAULT_BLOCK_SIZE * 2, source.length
- DEFAULT_BLOCK_SIZE * 2);
+
+        try {
+
+            Cipher decCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+
+            // 'trim' is to get rid of 0 padding
+            String keyName = new String(keyNameBytes, "UTF-8").trim();
+            Key key = runtime.getInjector().getInstance(KeySource.class).getKey(keyName);
+
+            decCipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(ivBytes));
+
+            return decCipher.doFinal(cipherText);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
 }

Modified: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtilsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtilsTest.java?rev=1584628&r1=1584627&r2=1584628&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtilsTest.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/CryptoUnitUtilsTest.java
Fri Apr  4 12:03:42 2014
@@ -37,5 +37,4 @@ public class CryptoUnitUtilsTest {
                 (byte) 0x20 };
         assertArrayEquals(hexByte2, CryptoUnitUtils.hexToBytes(hexString2));
     }
-
 }



Mime
View raw message