You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sd...@apache.org on 2016/06/24 08:16:39 UTC

[1/3] commons-crypto git commit: CRYPTO-82: CipherTransformation is an enum which limits the possible transformations delete enum getTransformation, use String type transformation. And add two methods getAlgorithm() / getBlockSize for CryptoCipher, keep

Repository: commons-crypto
Updated Branches:
  refs/heads/master 6529207de -> e90580a89


CRYPTO-82: CipherTransformation is an enum which limits the possible transformations
delete enum getTransformation, use String type transformation.
And add two methods getAlgorithm() / getBlockSize for CryptoCipher, keep similar to JCE


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/9f1e2015
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/9f1e2015
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/9f1e2015

Branch: refs/heads/master
Commit: 9f1e2015dfe93b472e265c3feac49ea5e6d62c85
Parents: 6529207
Author: Xianda Ke <xi...@intel.com>
Authored: Wed Jun 22 13:38:21 2016 +0800
Committer: Xianda Ke <xi...@intel.com>
Committed: Fri Jun 24 15:19:01 2016 +0800

----------------------------------------------------------------------
 .../crypto/cipher/CipherTransformation.java     | 98 --------------------
 .../commons/crypto/cipher/CryptoCipher.java     | 18 +++-
 .../crypto/cipher/CryptoCipherFactory.java      | 11 ++-
 .../apache/commons/crypto/cipher/JceCipher.java | 32 +++++--
 .../commons/crypto/cipher/OpensslCipher.java    | 32 +++++--
 .../crypto/examples/CipherByteArrayExample.java |  3 +-
 .../examples/CipherByteBufferExample.java       |  3 +-
 .../commons/crypto/examples/StreamExample.java  |  3 +-
 .../crypto/stream/CTRCryptoInputStream.java     | 10 +-
 .../crypto/stream/CTRCryptoOutputStream.java    | 10 +-
 .../crypto/stream/CryptoInputStream.java        | 17 ++--
 .../crypto/stream/CryptoOutputStream.java       | 17 ++--
 .../stream/PositionedCryptoInputStream.java     |  6 +-
 .../org/apache/commons/crypto/utils/Utils.java  | 15 +--
 src/site/xdoc/userguide.xml                     |  8 +-
 .../crypto/cipher/AbstractCipherTest.java       | 20 ++--
 .../crypto/cipher/CryptoCipherFactoryTest.java  |  8 +-
 .../commons/crypto/cipher/JceCipherTest.java    |  8 +-
 .../crypto/cipher/OpensslCipherTest.java        | 16 ++--
 .../apache/commons/crypto/cipher/TestData.java  | 10 +-
 .../crypto/stream/AbstractCipherStreamTest.java |  3 +-
 .../stream/CBCNoPaddingCipherStreamTest.java    |  4 +-
 .../stream/CBCPKCS5PaddingCipherStreamTest.java |  4 +-
 .../crypto/stream/CTRCryptoStreamTest.java      |  3 +-
 .../stream/CTRNoPaddingCipherStreamTest.java    |  4 +-
 .../stream/PositionedCryptoInputStreamTest.java |  3 +-
 26 files changed, 153 insertions(+), 213 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/cipher/CipherTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CipherTransformation.java b/src/main/java/org/apache/commons/crypto/cipher/CipherTransformation.java
deleted file mode 100644
index 9a6a358..0000000
--- a/src/main/java/org/apache/commons/crypto/cipher/CipherTransformation.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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.commons.crypto.cipher;
-
-/**
- * Defines properties of a CipherTransformation. Modeled after the ciphers in
- * Cipher.
- */
-public enum CipherTransformation {
-
-    /** A crypto transformation representing AES/CTR/NoPadding */
-    AES_CTR_NOPADDING("AES/CTR/NoPadding", 16),
-    /** A crypto transformation representing AES/CBC/NoPadding */
-    AES_CBC_NOPADDING("AES/CBC/NoPadding", 16),
-    /** A crypto transformation representing AES/CBC/PKCS5Padding */
-    AES_CBC_PKCS5PADDING("AES/CBC/PKCS5Padding", 16);
-
-    private final String name;
-    private final int algorithmBlockSize;
-
-    /**
-     * Constructor for CipherTransformation. Initalizes the cipher with
-     * algorithm name and block size of the algorithm.
-     *
-     * @param name the name of cipher algorithm
-     * @param algorithmBlockSize the blockSize of cipher algorithm
-     */
-    CipherTransformation(String name, int algorithmBlockSize) {
-        this.name = name;
-        this.algorithmBlockSize = algorithmBlockSize;
-    }
-
-    /**
-     * Gets the algorithm name of cipher.
-     *
-     * @return name of cipher transformation, as in Cipher
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * Gets the algorithm block size of cipher.
-     *
-     * @return size of an algorithm block in bytes.
-     */
-    public int getAlgorithmBlockSize() {
-        return algorithmBlockSize;
-    }
-
-    /**
-     * Overrides {@link java.lang.Enum#toString()}
-     *
-     * @return the name of cipher algorithm and blocksize.
-     */
-    @Override
-    public String toString() {
-        StringBuilder builder = new StringBuilder("{");
-        builder.append("name: " + name);
-        builder.append(", algorithmBlockSize: " + algorithmBlockSize);
-        builder.append("}");
-        return builder.toString();
-    }
-
-    /**
-     * Converts to CipherTransformation from name, {@link #algorithmBlockSize}
-     * is fixed for certain cipher transformation, just need to compare the
-     * name.
-     *
-     * @param name cipher transformation name
-     * @return CipherTransformation cipher transformation
-     */
-    public static CipherTransformation fromName(String name) {
-        CipherTransformation[] transformations = CipherTransformation.values();
-        for (CipherTransformation transformation : transformations) {
-            if (transformation.getName().equals(name)) {
-                return transformation;
-            }
-        }
-        throw new IllegalArgumentException("Invalid transformation name: "
-                + name);
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
index 5933a1d..12f2793 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
@@ -37,11 +37,23 @@ import javax.crypto.ShortBufferException;
 public interface CryptoCipher extends Closeable {
 
     /**
-     * Gets the CipherTransformation for this cipher.
+     * Returns the block size (in bytes).
      *
-     * @return the CipherTransformation for this cipher.
+     * @return the block size (in bytes), or 0 if the underlying algorithm is
+     * not a block cipher
      */
-    CipherTransformation getTransformation();
+    int getBlockSize();
+
+    /**
+     * Returns the algorithm name of this {@code CryptoCipher} object.
+     *
+     * <p>This is the same name that was specified in one of the
+     * {@code CryptoCipherFactory#getInstance} calls that created this
+     * {@code CryptoCipher} object..
+     *
+     * @return the algorithm name of this {@code CryptoCipher} object.
+     */
+    String getAlgorithm();
 
     /**
      * Initializes the cipher with mode, key and iv.

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
index 307c90a..ac7bb68 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
@@ -44,7 +44,7 @@ public class CryptoCipherFactory {
      *         classes with transformation configured.
      * @throws GeneralSecurityException if cipher initialize failed
      */
-    public static CryptoCipher getInstance(CipherTransformation transformation,
+    public static CryptoCipher getInstance(String transformation,
             Properties props) throws GeneralSecurityException {
 
         List<String> klasses =  Utils.splitClassNames(
@@ -73,7 +73,7 @@ public class CryptoCipherFactory {
             return new JceCipher(props,transformation);
         } else {
             errorMessage.append(" is not available or transformation " +
-                    transformation.getName() + " is not supported.");
+                    transformation + " is not supported.");
             throw new GeneralSecurityException(errorMessage.toString());
         }
     }
@@ -82,12 +82,15 @@ public class CryptoCipherFactory {
      * Gets a cipher for algorithm/mode/padding in config value
      * commons.crypto.cipher.transformation
      *
-     * @param transformation CipherTransformation instance.
+     * @param transformation the name of the transformation, e.g.,
+     * <i>AES/CBC/PKCS5Padding</i>.
+     * See the Java Cryptography Architecture Standard Algorithm Name Documentation
+     * for information about standard transformation names.
      * @return CryptoCipher the cipher object Null value will be returned if no
      *         cipher classes with transformation configured.
      * @throws GeneralSecurityException if JCE cipher initialize failed
      */
-    public static CryptoCipher getInstance(CipherTransformation transformation)
+    public static CryptoCipher getInstance(String transformation)
             throws GeneralSecurityException {
         return getInstance(transformation, new Properties());
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java b/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
index e39ef0a..7dcd606 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
@@ -37,7 +37,6 @@ import org.apache.commons.crypto.utils.Utils;
  * Implements the {@link CryptoCipher} using JCE provider.
  */
 public class JceCipher implements CryptoCipher {
-    private final CipherTransformation transformation;
     private final Cipher cipher;
 
     /**
@@ -47,26 +46,39 @@ public class JceCipher implements CryptoCipher {
      * @param transformation transformation for JCE cipher
      * @throws GeneralSecurityException if JCE cipher initialize failed
      */
-    public JceCipher(Properties props, CipherTransformation transformation)
+    public JceCipher(Properties props, String transformation)
             throws GeneralSecurityException {
-        this.transformation = transformation;
-
         String provider = getJCEProvider(props);
         if (provider == null || provider.isEmpty()) {
-            cipher = Cipher.getInstance(transformation.getName());
+            cipher = Cipher.getInstance(transformation);
         } else {
-            cipher = Cipher.getInstance(transformation.getName(), provider);
+            cipher = Cipher.getInstance(transformation, provider);
         }
     }
 
     /**
-     * Gets the CipherTransformation for the jce cipher.
+     * Returns the block size (in bytes).
+     *
+     * @return the block size (in bytes), or 0 if the underlying algorithm is
+     * not a block cipher
+     */
+    @Override
+    public final int getBlockSize() {
+        return cipher.getBlockSize();
+    }
+
+    /**
+     * Returns the algorithm name of this {@code CryptoCipher} object.
+     *
+     * <p>This is the same name that was specified in one of the
+     * {@code CryptoCipherFactory#getInstance} calls that created this
+     * {@code CryptoCipher} object..
      *
-     * @return the CipherTransformation for this cipher
+     * @return the algorithm name of this {@code CryptoCipher} object.
      */
     @Override
-    public CipherTransformation getTransformation() {
-        return transformation;
+    public String getAlgorithm() {
+        return cipher.getAlgorithm();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java b/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
index 4d01712..1cfd3e8 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
@@ -36,9 +36,13 @@ import org.apache.commons.crypto.utils.Utils;
  * Implements the CryptoCipher using JNI into OpenSSL.
  */
 public class OpensslCipher implements CryptoCipher {
-    private final CipherTransformation transformation;
+
     private final Openssl cipher;
 
+    private final String transformation;
+
+    private final static int AES_BLOCK_SIZE = 16;
+
     /**
      * Constructs a {@link CryptoCipher} using JNI into OpenSSL
      *
@@ -46,8 +50,7 @@ public class OpensslCipher implements CryptoCipher {
      * @param transformation transformation for OpenSSL cipher
      * @throws GeneralSecurityException if OpenSSL cipher initialize failed
      */
-    public OpensslCipher(Properties props, CipherTransformation  // NOPMD
-        transformation)
+    public OpensslCipher(Properties props, String transformation)
             throws GeneralSecurityException {
         this.transformation = transformation;
 
@@ -56,16 +59,31 @@ public class OpensslCipher implements CryptoCipher {
             throw new RuntimeException(loadingFailureReason);
         }
 
-        cipher = Openssl.getInstance(transformation.getName());
+        cipher = Openssl.getInstance(transformation);
+    }
+
+    /**
+     * Returns the block size (in bytes).
+     *
+     * @return the block size (in bytes), or 0 if the underlying algorithm is
+     * not a block cipher
+     */
+    @Override
+    public final int getBlockSize() {
+        return AES_BLOCK_SIZE;
     }
 
     /**
-     * Gets the CipherTransformation for the openssl cipher.
+     * Returns the algorithm name of this {@code CryptoCipher} object.
+     *
+     * <p>This is the same name that was specified in one of the
+     * {@code CryptoCipherFactory#getInstance} calls that created this
+     * {@code CryptoCipher} object..
      *
-     * @return the CipherTransformation for this cipher
+     * @return the algorithm name of this {@code CryptoCipher} object.
      */
     @Override
-    public CipherTransformation getTransformation() {
+    public String getAlgorithm() {
         return transformation;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java b/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
index 36539a9..a0a6ea0 100644
--- a/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
@@ -25,7 +25,6 @@ import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.utils.Utils;
 
@@ -40,7 +39,7 @@ public class CipherByteArrayExample {
         final IvParameterSpec iv = new IvParameterSpec(getUTF8Bytes("1234567890123456"));
         Properties properties = new Properties();
         //Creates a CryptoCipher instance with the transformation and properties.
-        final CipherTransformation transform = CipherTransformation.AES_CBC_PKCS5PADDING;
+        final String transform = "AES/CBC/PKCS5Padding";
         CryptoCipher encipher = Utils.getCipherInstance(transform, properties);
 
         final String sampleInput = "hello world!";

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java b/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
index d9d1db6..e614a6c 100644
--- a/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
@@ -26,7 +26,6 @@ import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.utils.Utils;
 
@@ -48,7 +47,7 @@ public class CipherByteBufferExample {
         final IvParameterSpec iv = new IvParameterSpec(getUTF8Bytes("1234567890123456"));
         Properties properties = new Properties();
         //Creates a CryptoCipher instance with the transformation and properties.
-        final CipherTransformation transform = CipherTransformation.AES_CBC_PKCS5PADDING;
+        final String transform = "AES/CBC/PKCS5Padding";
         final ByteBuffer outBuffer;
         final int bufferSize = 1024;
         final int updateBytes;

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/StreamExample.java b/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
index 5927f80..8904cb1 100644
--- a/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
@@ -28,7 +28,6 @@ import java.util.Properties;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.stream.CryptoInputStream;
 import org.apache.commons.crypto.stream.CryptoOutputStream;
 
@@ -45,7 +44,7 @@ public class StreamExample {
         final SecretKeySpec key = new SecretKeySpec(getUTF8Bytes("1234567890123456"),"AES");
         final IvParameterSpec iv = new IvParameterSpec(getUTF8Bytes("1234567890123456"));
         Properties properties = new Properties();
-        final CipherTransformation transform = CipherTransformation.AES_CBC_PKCS5PADDING;
+        final String transform = "AES/CBC/PKCS5Padding";
 
         String input = "hello world!";
         //Encryption with CryptoOutputStream.

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
index 33a032d..df413d5 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoInputStream.java
@@ -31,7 +31,6 @@ import javax.crypto.ShortBufferException;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.stream.input.ChannelInput;
 import org.apache.commons.crypto.stream.input.Input;
@@ -169,7 +168,7 @@ public class CTRCryptoInputStream extends CryptoInputStream {
     public CTRCryptoInputStream(Properties props, InputStream in, byte[] key,
             byte[] iv, long streamOffset) throws IOException {
         this(in, Utils.getCipherInstance(
-                CipherTransformation.AES_CTR_NOPADDING, props), Utils
+                "AES/CTR/NoPadding", props), Utils
                 .getBufferSize(props), key, iv, streamOffset);
     }
 
@@ -187,7 +186,7 @@ public class CTRCryptoInputStream extends CryptoInputStream {
     public CTRCryptoInputStream(Properties props, ReadableByteChannel in,
             byte[] key, byte[] iv, long streamOffset) throws IOException {
         this(in, Utils.getCipherInstance(
-                CipherTransformation.AES_CTR_NOPADDING, props), Utils
+                "AES/CTR/NoPadding", props), Utils
                 .getBufferSize(props), key, iv, streamOffset);
     }
 
@@ -535,7 +534,7 @@ public class CTRCryptoInputStream extends CryptoInputStream {
      * @return the counter for input stream position.
      */
     protected long getCounter(long position) {
-        return position / cipher.getTransformation().getAlgorithmBlockSize();
+        return position / cipher.getBlockSize();
     }
 
     /**
@@ -545,8 +544,7 @@ public class CTRCryptoInputStream extends CryptoInputStream {
      * @return the padding for input stream position.
      */
     protected byte getPadding(long position) {
-        return (byte) (position % cipher.getTransformation()
-                .getAlgorithmBlockSize());
+        return (byte) (position % cipher.getBlockSize());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
index 7d13a39..b5e39f2 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CTRCryptoOutputStream.java
@@ -31,7 +31,6 @@ import javax.crypto.ShortBufferException;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.stream.output.ChannelOutput;
 import org.apache.commons.crypto.stream.output.Output;
@@ -169,7 +168,7 @@ public class CTRCryptoOutputStream extends CryptoOutputStream {
     public CTRCryptoOutputStream(Properties props, OutputStream out,
             byte[] key, byte[] iv, long streamOffset) throws IOException {
         this(out, Utils.getCipherInstance(
-                CipherTransformation.AES_CTR_NOPADDING, props), Utils
+                "AES/CTR/NoPadding", props), Utils
                 .getBufferSize(props), key, iv, streamOffset);
     }
 
@@ -187,7 +186,7 @@ public class CTRCryptoOutputStream extends CryptoOutputStream {
     public CTRCryptoOutputStream(Properties props, WritableByteChannel out,
             byte[] key, byte[] iv, long streamOffset) throws IOException {
         this(out, Utils.getCipherInstance(
-                CipherTransformation.AES_CTR_NOPADDING, props), Utils
+                "AES/CTR/NoPadding", props), Utils
                 .getBufferSize(props), key, iv, streamOffset);
     }
 
@@ -322,9 +321,8 @@ public class CTRCryptoOutputStream extends CryptoOutputStream {
      */
     private void resetCipher() throws IOException {
         final long counter = streamOffset
-                / cipher.getTransformation().getAlgorithmBlockSize();
-        padding = (byte) (streamOffset % cipher.getTransformation()
-                .getAlgorithmBlockSize());
+                / cipher.getBlockSize();
+        padding = (byte) (streamOffset % cipher.getBlockSize());
         inBuffer.position(padding); // Set proper position for input data.
 
         Utils.calculateIV(initIV, counter, iv);

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
index faeda11..ad829da 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -32,7 +32,6 @@ import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.ShortBufferException;
 import javax.crypto.spec.IvParameterSpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.stream.input.ChannelInput;
 import org.apache.commons.crypto.stream.input.Input;
@@ -88,7 +87,10 @@ public class CryptoInputStream extends InputStream implements
     /**
      * Constructs a {@link CryptoInputStream}.
      *
-     * @param transformation the CipherTransformation instance.
+     * @param transformation the name of the transformation, e.g.,
+     * <i>AES/CBC/PKCS5Padding</i>.
+     * See the Java Cryptography Architecture Standard Algorithm Name Documentation
+     * for information about standard transformation names.
      * @param props The <code>Properties</code> class represents a set of
      *        properties.
      * @param in the input stream.
@@ -96,7 +98,7 @@ public class CryptoInputStream extends InputStream implements
      * @param params the algorithm parameters.
      * @throws IOException if an I/O error occurs.
      */
-    public CryptoInputStream(CipherTransformation transformation,
+    public CryptoInputStream(String transformation,
             Properties props, InputStream in, Key key,
             AlgorithmParameterSpec params) throws IOException {
         this(in, Utils.getCipherInstance(transformation, props), Utils
@@ -106,7 +108,10 @@ public class CryptoInputStream extends InputStream implements
     /**
      * Constructs a {@link CryptoInputStream}.
      *
-     * @param transformation the CipherTransformation instance.
+     * @param transformation the name of the transformation, e.g.,
+     * <i>AES/CBC/PKCS5Padding</i>.
+     * See the Java Cryptography Architecture Standard Algorithm Name Documentation
+     * for information about standard transformation names.
      * @param props The <code>Properties</code> class represents a set of
      *        properties.
      * @param in the ReadableByteChannel object.
@@ -114,7 +119,7 @@ public class CryptoInputStream extends InputStream implements
      * @param params the algorithm parameters.
      * @throws IOException if an I/O error occurs.
      */
-    public CryptoInputStream(CipherTransformation transformation,
+    public CryptoInputStream(String transformation,
             Properties props, ReadableByteChannel in, Key key,
             AlgorithmParameterSpec params) throws IOException {
         this(in, Utils.getCipherInstance(transformation, props), Utils
@@ -179,7 +184,7 @@ public class CryptoInputStream extends InputStream implements
 
         inBuffer = ByteBuffer.allocateDirect(this.bufferSize);
         outBuffer = ByteBuffer.allocateDirect(this.bufferSize
-                + cipher.getTransformation().getAlgorithmBlockSize());
+                + cipher.getBlockSize());
         outBuffer.limit(0);
 
         initCipher();

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
index b14d7fe..477fcf5 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
@@ -33,7 +33,6 @@ import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.ShortBufferException;
 import javax.crypto.spec.IvParameterSpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.stream.output.ChannelOutput;
 import org.apache.commons.crypto.stream.output.Output;
@@ -83,7 +82,10 @@ public class CryptoOutputStream extends OutputStream implements
     /**
      * Constructs a {@link CryptoOutputStream}.
      *
-     * @param transformation the CipherTransformation instance.
+     * @param transformation the name of the transformation, e.g.,
+     * <i>AES/CBC/PKCS5Padding</i>.
+     * See the Java Cryptography Architecture Standard Algorithm Name Documentation
+     * for information about standard transformation names.
      * @param props The <code>Properties</code> class represents a set of
      *        properties.
      * @param out the output stream.
@@ -92,7 +94,7 @@ public class CryptoOutputStream extends OutputStream implements
      * @throws IOException if an I/O error occurs.
      */
 
-    public CryptoOutputStream(CipherTransformation transformation,
+    public CryptoOutputStream(String transformation,
             Properties props, OutputStream out, Key key,
             AlgorithmParameterSpec params) throws IOException {
         this(out, Utils.getCipherInstance(transformation, props), Utils
@@ -103,7 +105,10 @@ public class CryptoOutputStream extends OutputStream implements
     /**
      * Constructs a {@link CryptoOutputStream}.
      *
-     * @param transformation the CipherTransformation instance.
+     * @param transformation the name of the transformation, e.g.,
+     * <i>AES/CBC/PKCS5Padding</i>.
+     * See the Java Cryptography Architecture Standard Algorithm Name Documentation
+     * for information about standard transformation names.
      * @param props The <code>Properties</code> class represents a set of
      *        properties.
      * @param out the WritableByteChannel instance.
@@ -111,7 +116,7 @@ public class CryptoOutputStream extends OutputStream implements
      * @param params the algorithm parameters.
      * @throws IOException if an I/O error occurs.
      */
-    public CryptoOutputStream(CipherTransformation transformation,
+    public CryptoOutputStream(String transformation,
             Properties props, WritableByteChannel out, Key key,
             AlgorithmParameterSpec params) throws IOException {
         this(out, Utils.getCipherInstance(transformation, props), Utils
@@ -180,7 +185,7 @@ public class CryptoOutputStream extends OutputStream implements
 
         inBuffer = ByteBuffer.allocateDirect(this.bufferSize);
         outBuffer = ByteBuffer.allocateDirect(this.bufferSize
-                + cipher.getTransformation().getAlgorithmBlockSize());
+                + cipher.getBlockSize());
 
         initCipher();
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
index 9a1d7bb..da565d1 100644
--- a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
@@ -36,7 +36,6 @@ import org.apache.commons.crypto.cipher.CryptoCipherFactory;
 import org.apache.commons.crypto.stream.input.Input;
 import org.apache.commons.crypto.utils.IOUtils;
 import org.apache.commons.crypto.utils.Utils;
-import static org.apache.commons.crypto.cipher.CipherTransformation.AES_CTR_NOPADDING;
 
 /**
  * PositionedCryptoInputStream provides the capability to decrypt the stream
@@ -73,7 +72,7 @@ public class PositionedCryptoInputStream extends CTRCryptoInputStream {
      */
     public PositionedCryptoInputStream(Properties props, Input in, byte[] key,
             byte[] iv, long streamOffset) throws IOException {
-        this(props, in, Utils.getCipherInstance(AES_CTR_NOPADDING, props),
+        this(props, in, Utils.getCipherInstance("AES/CTR/NoPadding", props),
                 Utils.getBufferSize(props), key, iv, streamOffset);
     }
 
@@ -320,8 +319,7 @@ public class PositionedCryptoInputStream extends CTRCryptoInputStream {
         if (state == null) {
             CryptoCipher cipher;
             try {
-                cipher = CryptoCipherFactory.getInstance(getCipher()
-                        .getTransformation(), props);
+                cipher = CryptoCipherFactory.getInstance("AES/CTR/NoPadding", props);
             } catch (GeneralSecurityException e) {
                 throw new IOException(e);
             }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/main/java/org/apache/commons/crypto/utils/Utils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/Utils.java b/src/main/java/org/apache/commons/crypto/utils/Utils.java
index 83a785f..fc1896d 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -27,7 +27,6 @@ import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.cipher.CryptoCipherFactory;
 import org.apache.commons.crypto.conf.ConfigurationKeys;
@@ -45,8 +44,7 @@ public final class Utils {
      * @see <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">
      *      http://en.wikipedia.org/wiki/Advanced_Encryption_Standard</a>
      */
-    private static final int AES_BLOCK_SIZE = CipherTransformation.AES_CTR_NOPADDING
-            .getAlgorithmBlockSize();
+    private static final int AES_BLOCK_SIZE = 16;
 
     /**
      * The private constructor of {@Link Utils}.
@@ -193,7 +191,7 @@ public final class Utils {
      */
     public static void checkStreamCipher(CryptoCipher cipher)
             throws IOException {
-        if (cipher.getTransformation() != CipherTransformation.AES_CTR_NOPADDING) {
+        if (!cipher.getAlgorithm().equals("AES/CTR/NoPadding")) {
             throw new IOException("AES/CTR/NoPadding is required");
         }
     }
@@ -209,7 +207,7 @@ public final class Utils {
         checkArgument(bufferSize >= MIN_BUFFER_SIZE,
                 "Minimum value of buffer size is " + MIN_BUFFER_SIZE + ".");
         return bufferSize - bufferSize
-                % cipher.getTransformation().getAlgorithmBlockSize();
+                % cipher.getBlockSize();
     }
 
     /**
@@ -259,12 +257,15 @@ public final class Utils {
      *
      * @param props The <code>Properties</code> class represents a set of
      *        properties.
-     * @param transformation the CipherTransformation instance.
+     * @param transformation the name of the transformation, e.g.,
+     * <i>AES/CBC/PKCS5Padding</i>.
+     * See the Java Cryptography Architecture Standard Algorithm Name Documentation
+     * for information about standard transformation names.
      * @return the CryptoCipher instance.
      * @throws IOException if an I/O error occurs.
      */
     public static CryptoCipher getCipherInstance(
-            CipherTransformation transformation, Properties props)
+            String transformation, Properties props)
             throws IOException {
         try {
             return CryptoCipherFactory.getInstance(transformation, props);

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/site/xdoc/userguide.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/userguide.xml b/src/site/xdoc/userguide.xml
index 44bb381..1bd965d 100644
--- a/src/site/xdoc/userguide.xml
+++ b/src/site/xdoc/userguide.xml
@@ -112,7 +112,7 @@
             <td>
               Properties properties = new Properties();<br/>
               //Creates a CryptoCipher instance with the transformation and properties.<br/>
-              CryptoCipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
+              CryptoCipher cipher = Utils.getCipherInstance("AES/CTR/NoPadding", properties);<br/><br/>
               String input = "hello world!";<br/>
               int inputOffset = 0;<br/>
               int inputLen = input.length();<br/>
@@ -136,7 +136,7 @@
             <td>
               Properties properties = new Properties();<br/>
               //Creates a Cipher instance with the transformation and properties.<br/>
-              CryptoCipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
+              CryptoCipher cipher = Utils.getCipherInstance("AES/CTR/NoPadding", properties);<br/><br/>
               int bufferSize = 4096;<br/>
               ByteBuffer inBuffer = ByteBuffer.allocateDirect(bufferSize);<br/>
               ByteBuffer outBuffer = ByteBuffer.allocateDirect(bufferSize);<br/>
@@ -170,7 +170,7 @@
               // Constructs the original OutputStream.<br/>
               OutputStream outputStream = new ByteArrayOutputStream();<br/>
               //Creates a CryptoCipher instance with the transformation and properties.<br/>
-              CryptoCipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
+              CryptoCipher cipher = Utils.getCipherInstance("AES/CTR/NoPadding", properties);<br/><br/>
               //Constructs the instance of CryptoOutputStream.<br/>
               CryptoOutputStream cos = new CryptoOutputStream(outputStream, cipher, bufferSize,<br/>
                                                               new SecretKeySpec(key,"AES"), new IvParameterSpec(iv));<br/>
@@ -188,7 +188,7 @@
               //Constructs the original InputStream.<br/>
               InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());<br/>
               //Creates a CryptoCipher instance with the transformation and properties.<br/>
-              CryptoCipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
+              CryptoCipher cipher = Utils.getCipherInstance(C"AES/CTR/NoPadding", properties);<br/><br/>
               //Constructs the instance of CryptoInputStream.<br/>
               CryptoInputStream cis = new CryptoInputStream(inputStream, cipher, bufferSize, <br/>
                                                             new SecretKeySpec(key,"AES"), new IvParameterSpec(iv));<br/>

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
index 4fb7a8e..ee69a06 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
@@ -42,7 +42,7 @@ public abstract class AbstractCipherTest {
     public String[] cipherTests = null;
     Properties props = null;
     String cipherClass = null;
-    CipherTransformation[] transformations = null;
+    String[] transformations = null;
 
     // cipher
     static final byte[] KEY = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
@@ -65,7 +65,7 @@ public abstract class AbstractCipherTest {
 
     @Test
     public void cryptoTest() throws GeneralSecurityException {
-        for (CipherTransformation tran : transformations) {
+        for (String tran : transformations) {
             /** uses the small data set in {@link TestData} */
             cipherTests = TestData.getTestData(tran);
             for (int i = 0; i != cipherTests.length; i += 5) {
@@ -97,7 +97,7 @@ public abstract class AbstractCipherTest {
         }
     }
 
-    private void byteBufferTest(CipherTransformation transformation,
+    private void byteBufferTest(String transformation,
             byte[] key, byte[] iv, ByteBuffer input, ByteBuffer output)
             throws GeneralSecurityException {
         ByteBuffer decResult = ByteBuffer.allocateDirect(BYTEBUFFER_SIZE);
@@ -153,11 +153,11 @@ public abstract class AbstractCipherTest {
     }
 
     /** test byte array whose data is planned in {@link TestData} */
-    private void byteArrayTest(CipherTransformation transformation, byte[] key,
+    private void byteArrayTest(String transformation, byte[] key,
             byte[] iv, byte[] input, byte[] output)
             throws GeneralSecurityException {
         resetCipher(transformation, key, iv);
-        int blockSize = transformation.getAlgorithmBlockSize();
+        int blockSize = enc.getBlockSize();
 
         byte[] temp = new byte[input.length + blockSize];
         int n = enc.doFinal(input, 0, input.length, temp, 0);
@@ -175,13 +175,13 @@ public abstract class AbstractCipherTest {
     }
 
     /** test byte array whose data is randomly generated */
-    private void byteArrayTest(CipherTransformation transformation, byte[] key,
+    private void byteArrayTest(String transformation, byte[] key,
             byte[] iv) throws GeneralSecurityException {
-        int blockSize = transformation.getAlgorithmBlockSize();
+        int blockSize = enc.getBlockSize();
 
         // AES_CBC_NOPADDING only accepts data whose size is the multiple of
         // block size
-        int[] dataLenList = (transformation == CipherTransformation.AES_CBC_NOPADDING) ? new int[] { 10 * 1024 }
+        int[] dataLenList = (transformation.equals("AES/CBC/NoPadding")) ? new int[] { 10 * 1024 }
                 : new int[] { 10 * 1024, 10 * 1024 - 3 };
         for (int dataLen : dataLenList) {
             byte[] plainText = new byte[dataLen];
@@ -232,7 +232,7 @@ public abstract class AbstractCipherTest {
         }
     }
 
-    private void resetCipher(CipherTransformation transformation, byte[] key,
+    private void resetCipher(String transformation, byte[] key,
             byte[] iv) {
         enc = getCipher(transformation);
         dec = getCipher(transformation);
@@ -252,7 +252,7 @@ public abstract class AbstractCipherTest {
         }
     }
 
-    private CryptoCipher getCipher(CipherTransformation transformation) {
+    private CryptoCipher getCipher(String transformation) {
         try {
             return (CryptoCipher) ReflectionUtils.newInstance(
                     ReflectionUtils.getClassByName(cipherClass), props,

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
index a63a458..aeb4be0 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
@@ -29,7 +29,7 @@ public class CryptoCipherFactoryTest {
     @Test
     public void testDefaultCipher() throws GeneralSecurityException {
         CryptoCipher defaultCipher = CryptoCipherFactory
-                .getInstance(CipherTransformation.AES_CBC_NOPADDING);
+                .getInstance("AES/CBC/NoPadding");
         Assert.assertEquals(OpensslCipher.class.getName(), defaultCipher
                 .getClass().getName());
     }
@@ -40,7 +40,7 @@ public class CryptoCipherFactoryTest {
         properties.setProperty(
                 ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY, "");
         CryptoCipher defaultCipher = CryptoCipherFactory.getInstance(
-                CipherTransformation.AES_CBC_NOPADDING, properties);
+                "AES/CBC/NoPadding", properties);
         Assert.assertEquals(OpensslCipher.class.getName(), defaultCipher
                 .getClass().getName());
     }
@@ -51,7 +51,7 @@ public class CryptoCipherFactoryTest {
         properties.setProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY,
                 "InvalidCipherName");
         CryptoCipher defaultCipher = CryptoCipherFactory.getInstance(
-                CipherTransformation.AES_CBC_NOPADDING, properties);
+                "AES/CBC/NoPadding", properties);
         Assert.assertEquals(JceCipher.class.getName(), defaultCipher.getClass()
                 .getName());
     }
@@ -65,6 +65,6 @@ public class CryptoCipherFactoryTest {
         properties.setProperty(ConfigurationKeys
             .COMMONS_CRYPTO_ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY, "false");
 
-        CryptoCipherFactory.getInstance(CipherTransformation.AES_CBC_NOPADDING, properties);
+        CryptoCipherFactory.getInstance("AES/CBC/NoPadding", properties);
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/cipher/JceCipherTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/JceCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/JceCipherTest.java
index 2f28b16..6f72b7c 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/JceCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/JceCipherTest.java
@@ -31,10 +31,10 @@ public class JceCipherTest extends AbstractCipherTest {
 
     @Override
     public void init() {
-        transformations = new CipherTransformation[] {
-                CipherTransformation.AES_CBC_NOPADDING,
-                CipherTransformation.AES_CBC_PKCS5PADDING,
-                CipherTransformation.AES_CTR_NOPADDING };
+        transformations = new String[] {
+                "AES/CBC/NoPadding",
+                "AES/CBC/PKCS5Padding",
+                "AES/CTR/NoPadding"};
         cipherClass = JceCipher.class.getName();
     }
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/cipher/OpensslCipherTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/OpensslCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/OpensslCipherTest.java
index 0eaccb3..1150d25 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/OpensslCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/OpensslCipherTest.java
@@ -33,10 +33,10 @@ public class OpensslCipherTest extends AbstractCipherTest {
 
     @Override
     public void init() {
-        transformations = new CipherTransformation[] {
-                CipherTransformation.AES_CBC_NOPADDING,
-                CipherTransformation.AES_CBC_PKCS5PADDING,
-                CipherTransformation.AES_CTR_NOPADDING };
+        transformations = new String[] {
+                "AES/CBC/NoPadding",
+                "AES/CBC/PKCS5Padding",
+                "AES/CTR/NoPadding"};
         cipherClass = OpensslCipher.class.getName();
     }
 
@@ -85,7 +85,7 @@ public class OpensslCipherTest extends AbstractCipherTest {
     public void testUpdateArguments() throws Exception {
         Assume.assumeTrue(Openssl.getLoadingFailureReason() == null);
         Openssl cipher = Openssl
-                .getInstance(CipherTransformation.AES_CTR_NOPADDING.getName());
+                .getInstance("AES/CTR/NoPadding");
         Assert.assertNotNull(cipher);
 
         cipher.init(Openssl.ENCRYPT_MODE, KEY, IV);
@@ -119,7 +119,7 @@ public class OpensslCipherTest extends AbstractCipherTest {
     public void testDoFinalArguments() throws Exception {
         Assume.assumeTrue(Openssl.getLoadingFailureReason() == null);
         Openssl cipher = Openssl
-                .getInstance(CipherTransformation.AES_CTR_NOPADDING.getName());
+                .getInstance("AES/CTR/NoPadding");
         Assert.assertNotNull(cipher);
 
         cipher.init(Openssl.ENCRYPT_MODE, KEY, IV);
@@ -140,7 +140,7 @@ public class OpensslCipherTest extends AbstractCipherTest {
     public void testInvalidKey() throws Exception {
         Assume.assumeTrue(Openssl.getLoadingFailureReason() == null);
         Openssl cipher = Openssl
-                .getInstance(CipherTransformation.AES_CTR_NOPADDING.getName());
+                .getInstance("AES/CTR/NoPadding");
         Assert.assertNotNull(cipher);
 
         final byte[] invalidKey = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
@@ -158,7 +158,7 @@ public class OpensslCipherTest extends AbstractCipherTest {
     public void testInvalidIV() throws Exception {
         Assume.assumeTrue(Openssl.getLoadingFailureReason() == null);
         Openssl cipher = Openssl
-                .getInstance(CipherTransformation.AES_CTR_NOPADDING.getName());
+                .getInstance("AES/CTR/NoPadding");
         Assert.assertNotNull(cipher);
 
         final byte[] invalidIV = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/cipher/TestData.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/TestData.java b/src/test/java/org/apache/commons/crypto/cipher/TestData.java
index 397ecf1..a507325 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/TestData.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/TestData.java
@@ -136,16 +136,16 @@ public class TestData {
             "f0f1f2f3f4f5f6f7f8f9fafbfcfdff01",
             "30c81c46a35ce411e5fbc1191a0a52", "2b0930daa23de94ce87017ba2d8498" };
 
-    private static Map<CipherTransformation, String[]> testData = new HashMap<>();
+    private static Map<String, String[]> testData = new HashMap<>();
 
     static {
-        testData.put(CipherTransformation.AES_CBC_NOPADDING, CBCNoPaddingTests);
-        testData.put(CipherTransformation.AES_CBC_PKCS5PADDING,
+        testData.put("AES/CBC/NoPadding", CBCNoPaddingTests);
+        testData.put("AES/CBC/PKCS5Padding",
                 CBCPKCS5PaddingTests);
-        testData.put(CipherTransformation.AES_CTR_NOPADDING, cipherCTRTests);
+        testData.put("AES/CTR/NoPadding", cipherCTRTests);
     }
 
-    public static String[] getTestData(CipherTransformation transformation) {
+    public static String[] getTestData(String transformation) {
         return testData.get(transformation);
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
index c055616..bb587f4 100644
--- a/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/AbstractCipherStreamTest.java
@@ -33,7 +33,6 @@ import java.util.Random;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.cipher.JceCipher;
 import org.apache.commons.crypto.cipher.OpensslCipher;
@@ -56,7 +55,7 @@ public abstract class AbstractCipherStreamTest {
 
     private final String jceCipherClass = JceCipher.class.getName();
     private final String opensslCipherClass = OpensslCipher.class.getName();
-    protected CipherTransformation transformation;
+    protected String transformation;
 
     public abstract void setUp() throws IOException;
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/stream/CBCNoPaddingCipherStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/CBCNoPaddingCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/CBCNoPaddingCipherStreamTest.java
index fcf569d..4fb21b6 100644
--- a/src/test/java/org/apache/commons/crypto/stream/CBCNoPaddingCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/CBCNoPaddingCipherStreamTest.java
@@ -19,13 +19,11 @@ package org.apache.commons.crypto.stream;
 
 import java.io.IOException;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
-
 public class CBCNoPaddingCipherStreamTest extends AbstractCipherStreamTest {
 
     @Override
     public void setUp() throws IOException {
-        transformation = CipherTransformation.AES_CBC_NOPADDING;
+        transformation = "AES/CBC/NoPadding";
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/stream/CBCPKCS5PaddingCipherStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/CBCPKCS5PaddingCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/CBCPKCS5PaddingCipherStreamTest.java
index 830b970..99cd31f 100644
--- a/src/test/java/org/apache/commons/crypto/stream/CBCPKCS5PaddingCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/CBCPKCS5PaddingCipherStreamTest.java
@@ -19,12 +19,10 @@ package org.apache.commons.crypto.stream;
 
 import java.io.IOException;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
-
 public class CBCPKCS5PaddingCipherStreamTest extends AbstractCipherStreamTest {
 
     @Override
     public void setUp() throws IOException {
-        transformation = CipherTransformation.AES_CBC_PKCS5PADDING;
+        transformation = "AES/CBC/PKCS5Padding";
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/stream/CTRCryptoStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/CTRCryptoStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/CTRCryptoStreamTest.java
index 4a87a9b..3ba55ec 100644
--- a/src/test/java/org/apache/commons/crypto/stream/CTRCryptoStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/CTRCryptoStreamTest.java
@@ -23,13 +23,12 @@ import java.io.IOException;
 import java.nio.channels.Channels;
 
 import org.apache.commons.crypto.cipher.CryptoCipher;
-import org.apache.commons.crypto.cipher.CipherTransformation;
 
 public class CTRCryptoStreamTest extends AbstractCipherStreamTest {
 
     @Override
     public void setUp() throws IOException {
-        transformation = CipherTransformation.AES_CTR_NOPADDING;
+        transformation = "AES/CTR/NoPadding";
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/stream/CTRNoPaddingCipherStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/CTRNoPaddingCipherStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/CTRNoPaddingCipherStreamTest.java
index 2638a39..76b8a7e 100644
--- a/src/test/java/org/apache/commons/crypto/stream/CTRNoPaddingCipherStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/CTRNoPaddingCipherStreamTest.java
@@ -19,13 +19,11 @@ package org.apache.commons.crypto.stream;
 
 import java.io.IOException;
 
-import org.apache.commons.crypto.cipher.CipherTransformation;
-
 public class CTRNoPaddingCipherStreamTest extends AbstractCipherStreamTest {
 
     @Override
     public void setUp() throws IOException {
-        transformation = CipherTransformation.AES_CTR_NOPADDING;
+        transformation = "AES/CTR/NoPadding";
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9f1e2015/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
index 7f6bf4e..a9c11e4 100644
--- a/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
+++ b/src/test/java/org/apache/commons/crypto/stream/PositionedCryptoInputStreamTest.java
@@ -19,7 +19,6 @@
 package org.apache.commons.crypto.stream;
 
 import org.apache.commons.crypto.cipher.CryptoCipher;
-import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.JceCipher;
 import org.apache.commons.crypto.cipher.OpensslCipher;
 import org.apache.commons.crypto.stream.input.Input;
@@ -56,7 +55,7 @@ public class PositionedCryptoInputStreamTest {
 
     private final String jceCipherClass = JceCipher.class.getName();
     private final String opensslCipherClass = OpensslCipher.class.getName();
-    private CipherTransformation transformation = CipherTransformation.AES_CTR_NOPADDING;
+    private String transformation = "AES/CTR/NoPadding";
 
     @Before
     public void before() throws IOException {


[2/3] commons-crypto git commit: Merge branch 'CRYPTO-82'

Posted by sd...@apache.org.
Merge branch 'CRYPTO-82'


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/6ac3e74f
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/6ac3e74f
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/6ac3e74f

Branch: refs/heads/master
Commit: 6ac3e74faef0d4f0fb92786d540505bcd2a808b4
Parents: 6529207 9f1e201
Author: Sun Dapeng <sd...@apache.org>
Authored: Fri Jun 24 16:10:59 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Fri Jun 24 16:10:59 2016 +0800

----------------------------------------------------------------------
 .../crypto/cipher/CipherTransformation.java     | 98 --------------------
 .../commons/crypto/cipher/CryptoCipher.java     | 18 +++-
 .../crypto/cipher/CryptoCipherFactory.java      | 11 ++-
 .../apache/commons/crypto/cipher/JceCipher.java | 32 +++++--
 .../commons/crypto/cipher/OpensslCipher.java    | 32 +++++--
 .../crypto/examples/CipherByteArrayExample.java |  3 +-
 .../examples/CipherByteBufferExample.java       |  3 +-
 .../commons/crypto/examples/StreamExample.java  |  3 +-
 .../crypto/stream/CTRCryptoInputStream.java     | 10 +-
 .../crypto/stream/CTRCryptoOutputStream.java    | 10 +-
 .../crypto/stream/CryptoInputStream.java        | 17 ++--
 .../crypto/stream/CryptoOutputStream.java       | 17 ++--
 .../stream/PositionedCryptoInputStream.java     |  6 +-
 .../org/apache/commons/crypto/utils/Utils.java  | 15 +--
 src/site/xdoc/userguide.xml                     |  8 +-
 .../crypto/cipher/AbstractCipherTest.java       | 20 ++--
 .../crypto/cipher/CryptoCipherFactoryTest.java  |  8 +-
 .../commons/crypto/cipher/JceCipherTest.java    |  8 +-
 .../crypto/cipher/OpensslCipherTest.java        | 16 ++--
 .../apache/commons/crypto/cipher/TestData.java  | 10 +-
 .../crypto/stream/AbstractCipherStreamTest.java |  3 +-
 .../stream/CBCNoPaddingCipherStreamTest.java    |  4 +-
 .../stream/CBCPKCS5PaddingCipherStreamTest.java |  4 +-
 .../crypto/stream/CTRCryptoStreamTest.java      |  3 +-
 .../stream/CTRNoPaddingCipherStreamTest.java    |  4 +-
 .../stream/PositionedCryptoInputStreamTest.java |  3 +-
 26 files changed, 153 insertions(+), 213 deletions(-)
----------------------------------------------------------------------



[3/3] commons-crypto git commit: CRYPTO-82: Add Unit Test for InvalidTransformation

Posted by sd...@apache.org.
CRYPTO-82: Add Unit Test for InvalidTransformation


Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/e90580a8
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/e90580a8
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/e90580a8

Branch: refs/heads/master
Commit: e90580a892a75ac6350a5a96c70a6a36b696879e
Parents: 6ac3e74
Author: Sun Dapeng <sd...@apache.org>
Authored: Fri Jun 24 16:12:36 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Fri Jun 24 16:12:36 2016 +0800

----------------------------------------------------------------------
 .../commons/crypto/cipher/CryptoCipherFactoryTest.java    | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/e90580a8/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
index aeb4be0..0adf826 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
@@ -52,8 +52,8 @@ public class CryptoCipherFactoryTest {
                 "InvalidCipherName");
         CryptoCipher defaultCipher = CryptoCipherFactory.getInstance(
                 "AES/CBC/NoPadding", properties);
-        Assert.assertEquals(JceCipher.class.getName(), defaultCipher.getClass()
-                .getName());
+        Assert.assertEquals(JceCipher.class.getName(),
+            defaultCipher.getClass().getName());
     }
 
     @Test(expected = GeneralSecurityException.class)
@@ -67,4 +67,10 @@ public class CryptoCipherFactoryTest {
 
         CryptoCipherFactory.getInstance("AES/CBC/NoPadding", properties);
     }
+
+    @Test(expected = GeneralSecurityException.class)
+    public void testInvalidTransformation() throws GeneralSecurityException {
+      Properties properties = new Properties();
+      CryptoCipherFactory.getInstance("AES/Invalid/NoPadding", properties);
+    }
 }