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/04/29 11:11:12 UTC

[5/5] commons-crypto git commit: CRYPTO-33: avoid shadowing JVM class renaming Cipher/Stream/Random classes

CRYPTO-33: avoid shadowing JVM class
renaming Cipher/Stream/Random classes


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

Branch: refs/heads/master
Commit: ea89d8023ed7c2a88c468df15994bdd9db922242
Parents: b532288
Author: Xianda Ke <xi...@intel.com>
Authored: Thu Apr 28 11:33:43 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Fri Apr 29 17:07:42 2016 +0800

----------------------------------------------------------------------
 Makefile                                        |  10 +-
 README.md                                       |  85 +--
 .../apache/commons/crypto/cipher/Cipher.java    | 157 -----
 .../commons/crypto/cipher/CipherFactory.java    | 105 ----
 .../commons/crypto/cipher/CryptoCipher.java     | 157 +++++
 .../crypto/cipher/CryptoCipherFactory.java      | 105 ++++
 .../apache/commons/crypto/cipher/JceCipher.java |   6 +-
 .../apache/commons/crypto/cipher/Openssl.java   |   2 +-
 .../commons/crypto/cipher/OpensslCipher.java    |   6 +-
 .../commons/crypto/cipher/package-info.java     |   2 +-
 .../commons/crypto/conf/ConfigurationKeys.java  |  12 +-
 .../commons/crypto/random/CryptoRandom.java     |  36 ++
 .../crypto/random/CryptoRandomFactory.java      |  76 +++
 .../commons/crypto/random/JavaCryptoRandom.java |  76 +++
 .../commons/crypto/random/JavaSecureRandom.java |  76 ---
 .../crypto/random/OpensslCryptoRandom.java      | 143 +++++
 .../random/OpensslCryptoRandomNative.java       |  43 ++
 .../crypto/random/OpensslSecureRandom.java      | 143 -----
 .../random/OpensslSecureRandomNative.java       |  43 --
 .../commons/crypto/random/OsCryptoRandom.java   | 133 ++++
 .../commons/crypto/random/OsSecureRandom.java   | 133 ----
 .../commons/crypto/random/SecureRandom.java     |  36 --
 .../crypto/random/SecureRandomFactory.java      |  76 ---
 .../crypto/stream/CTRCipherInputStream.java     | 625 -------------------
 .../crypto/stream/CTRCipherOutputStream.java    | 385 ------------
 .../crypto/stream/CTRCryptoInputStream.java     | 625 +++++++++++++++++++
 .../crypto/stream/CTRCryptoOutputStream.java    | 385 ++++++++++++
 .../crypto/stream/CipherInputStream.java        | 559 -----------------
 .../crypto/stream/CipherOutputStream.java       | 438 -------------
 .../crypto/stream/CryptoInputStream.java        | 559 +++++++++++++++++
 .../crypto/stream/CryptoOutputStream.java       | 441 +++++++++++++
 .../stream/PositionedCipherInputStream.java     | 362 -----------
 .../stream/PositionedCryptoInputStream.java     | 362 +++++++++++
 .../crypto/stream/input/ChannelInput.java       |   2 +-
 .../commons/crypto/stream/input/Input.java      |   2 +-
 .../crypto/stream/input/StreamInput.java        |   2 +-
 .../crypto/stream/output/ChannelOutput.java     |   2 +-
 .../commons/crypto/stream/output/Output.java    |   2 +-
 .../crypto/stream/output/StreamOutput.java      |   4 +-
 .../commons/crypto/utils/ReflectionUtils.java   |   6 +-
 .../org/apache/commons/crypto/utils/Utils.java  |  26 +-
 .../crypto/random/OpensslCryptoRandomNative.c   | 335 ++++++++++
 .../crypto/random/OpensslSecureRandomNative.c   | 335 ----------
 src/site/xdoc/userguide.xml                     |  40 +-
 .../crypto/cipher/AbstractCipherTest.java       |  16 +-
 .../crypto/cipher/CipherFactoryTest.java        |  57 --
 .../crypto/cipher/CryptoCipherFactoryTest.java  |  57 ++
 .../crypto/random/AbstractRandomTest.java       |   6 +-
 .../crypto/random/TestJavaCryptoRandom.java     |  40 ++
 .../crypto/random/TestJavaSecureRandom.java     |  40 --
 .../crypto/random/TestOpensslCryptoRandom.java  |  40 ++
 .../crypto/random/TestOpensslSecureRandom.java  |  40 --
 .../crypto/random/TestOsCryptoRandom.java       |  28 +
 .../crypto/random/TestOsSecureRandom.java       |  28 -
 .../crypto/stream/AbstractCipherStreamTest.java |  81 ++-
 .../crypto/stream/CTRCipherStreamTest.java      |  59 --
 .../crypto/stream/CTRCryptoStreamTest.java      |  59 ++
 .../stream/PositionedCipherInputStreamTest.java | 384 ------------
 .../stream/PositionedCryptoInputStreamTest.java | 384 ++++++++++++
 59 files changed, 4201 insertions(+), 4276 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 0b356fc..9190e25 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ include Makefile.common
 MVN:=mvn
 
 COMMONS_CRYPTO_OUT:=$(TARGET)/$(commons-crypto)-$(os_arch)
-COMMONS_CRYPTO_OBJ:=$(addprefix $(COMMONS_CRYPTO_OUT)/,OpensslSecureRandom.o OpensslNative.o)
+COMMONS_CRYPTO_OBJ:=$(addprefix $(COMMONS_CRYPTO_OUT)/,OpensslCryptoRandom.o OpensslNative.o)
 
 ifeq ($(OS_NAME),SunOS)
   TAR:= gtar
@@ -20,21 +20,21 @@ $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpensslNative.class : $(S
 	@mkdir -p $(TARGET)/jni-classes
 	$(JAVAC) -source 1.6 -target 1.6 -d $(TARGET)/jni-classes -sourcepath $(SRC) $<
 
-$(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslSecureRandomNative.class : $(SRC)/org/apache/commons/crypto/random/OpensslSecureRandomNative.java
+$(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslCryptoRandomNative.class : $(SRC)/org/apache/commons/crypto/random/OpensslCryptoRandomNative.java
 	@mkdir -p $(TARGET)/jni-classes
 	$(JAVAC) -source 1.6 -target 1.6 -d $(TARGET)/jni-classes -sourcepath $(SRC) $<
 
 $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpensslNative.h: $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpensslNative.class
 	$(JAVAH) -force -classpath $(TARGET)/jni-classes -o $@ org.apache.commons.crypto.cipher.OpensslNative
 
-$(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslSecureRandomNative.h: $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslSecureRandomNative.class
-	$(JAVAH) -force -classpath $(TARGET)/jni-classes -o $@ org.apache.commons.crypto.random.OpensslSecureRandomNative
+$(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslCryptoRandomNative.h: $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslCryptoRandomNative.class
+	$(JAVAH) -force -classpath $(TARGET)/jni-classes -o $@ org.apache.commons.crypto.random.OpensslCryptoRandomNative
 
 $(COMMONS_CRYPTO_OUT)/OpensslNative.o : $(SRC_NATIVE)/org/apache/commons/crypto/cipher/OpensslNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/cipher/OpensslNative.h
 	@mkdir -p $(@D)
 	$(CC) $(CFLAGS) -c $< -o $@
 
-$(COMMONS_CRYPTO_OUT)/OpensslSecureRandom.o : $(SRC_NATIVE)/org/apache/commons/crypto/random/OpensslSecureRandomNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslSecureRandomNative.h
+$(COMMONS_CRYPTO_OUT)/OpensslCryptoRandom.o : $(SRC_NATIVE)/org/apache/commons/crypto/random/OpensslCryptoRandomNative.c $(TARGET)/jni-classes/org/apache/commons/crypto/random/OpensslCryptoRandomNative.h
 	@mkdir -p $(@D)
 	$(CC) $(CFLAGS) -c $< -o $@
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index fdde241..d6f01e3 100644
--- a/README.md
+++ b/README.md
@@ -1,87 +1,10 @@
-Chimera [![Build Status](https://travis-ci.org/intel-hadoop/chimera.svg?branch=master)](https://travis-ci.org/intel-hadoop/chimera) is a cryptographic library optimized with AES-NI (Advanced Encryption Standard New Instructions). It provides Java API for both cipher level and Java stream level. Developers can use it to implement high performance AES encryption/decryption with the minimum code and effort. Please note that Chimera doesn't implement the cryptographic algorithm such as AES directly. It wraps to Openssl or JCE which implement the algorithms.
+Apache Commons Crypto is a cryptographic library optimized with AES-NI (Advanced Encryption Standard New Instructions). It provides Java API for both cipher level and Java stream level. Developers can use it to implement high performance AES encryption/decryption with the minimum code and effort. Please note that Apache Commons Crypto doesn't implement the cryptographic algorithm such as AES directly. It wraps to Openssl or JCE which implement the algorithms.
 
 ## Features
   * Cipher API for low level cryptographic operations.
-  * Java stream API (CipherInputStream/CipherOutputStream) for high level stream encyrption/decryption.
+  * Java stream API (CryptoInputStream/CryptoOutputStream) for high level stream encyrption/decryption.
   * Both optimized with high performance AES encryption/decryption. (1400 MB/s - 1700 MB/s throughput in modern Xeon processors).
   * JNI-based implementation to achieve comparable performance to the native C++ version based on Openssl.
-  * Portable across various operating systems (currently only Linux); Chimera loads the library according to your machine environment (It looks system properties, `os.name` and `os.arch`). 
-  * Simple usage. Add the chimera-(version).jar file to your classpath.
+  * Portable across various operating systems (currently only Linux); Apache Commons Crypto loads the library according to your machine environment (It looks system properties, `os.name` and `os.arch`).
+  * Simple usage. Add the commons-crypto-(version).jar file to your classpath.
   * [Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). Free for both commercial and non-commercial use.
-
-## Download
-  * Release version: http://central.maven.org/maven2/org/apache/commons/crypto/chimera/
-  * Snapshot version (the latest beta version): https://oss.sonatype.org/content/repositories/snapshots/org/apache/commons/crypto/chimera/
-
-### Using with Maven
-  * Chimera is available from Maven's central repository:  <http://central.maven.org/maven2/org/apache/commons/crypto/chimera>
-
-Add the following dependency to your pom.xml:
-
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-crypto</artifactId>
-      <version>0.9.0</version>
-      <type>jar</type>
-      <scope>compile</scope>
-    </dependency>
-
-### Using with sbt
-
-```
-libraryDependencies += "org.apache.commons" % "commons-crypto" % "0.9.0"
-```
-
-## Usage 
-
-```java
-
-Properties properties = new Properties();
-properties.setProperty("chimera.crypto.cipher.classes", "org.apache.commons.crypto.cipher.OpensslCipher");
-
-Cipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);
-byte[] key = new byte[16];
-byte[] iv = new byte[16];
-int bufferSize = 4096;
-String input = "hello world!";
-byte[] decryptedData = new byte[1024];
-// Encrypt
-ByteArrayOutputStream os = new ByteArrayOutputStream();
-CipherOutputStream cos = new CipherOutputStream(os, cipher, bufferSize,
-                                                new SecretKeySpec(key,"AES"), new IvParameterSpec(iv));
-cos.write(input.getBytes("UTF-8"));
-cos.flush();
-cos.close();
-
-// Decrypt
-CipherInputStream cis = new CipherInputStream(new ByteArrayInputStream(os.toByteArray()), cipher, bufferSize,
-                                              new SecretKeySpec(key,"AES"), new IvParameterSpec(iv));
-int decryptedLen = cis.read(decryptedData, 0, 1024);
-
-```
-
-### Configuration
-Currently, two ciphers are supported: JceCipher and OpensslCipher, you can configure which cipher to use as follows:
-
-    $ java -Dchimera.crypto.cipher.classes=org.apache.commons.crypto.cipher.OpensslCipher Sample
-    $ java -Dchimera.crypto.cipher.classes=org.apache.commons.crypto.cipher.JceCipher Sample
-
-More detailed information about the configurations are as follows.
-
-| Property Name | Default | Meaning         |
-| --------------|---------|-------------------------|
-| chimera.crypto.cipher.transformation | AES/CTR/NoPadding | The value is identical to the transformations described in the Cipher section of the Java Cryptography Architecture Standard Algorithm Name Documentation. Currently only "AES/CTR/NoPadding" algorithm is supported.|
-| chimera.crypto.cipher.classes | org.apache.commons.crypto.cipher.OpensslCipher, org.apache.commons.crypto.cipher.JceCipher | Comma-separated list of cipher classes which implement cipher algorithm of "AES/CTR/NoPadding". A cipher implementation encapsulates the encryption and decryption details. The first  available implementation appearing in this list will be used. |
-
-## Building from the source code
-Building from the source code is an option when your OS platform and CPU architecture is not supported. To build Chimera, you need JDK 1.7 or higher, OpenSSL 1.0.1c or higher, etc.
-
-    $ git clone https://github.com/intel-hadoop/chimera.git
-    $ cd chimera
-    $ mvn clean install
-
-A file `target/chimera-$(version).jar` is the product additionally containing the native library built for your platform.
-
-## Discussion
-For development related discussion, please go to [dev google group](https://groups.google.com/forum/#!forum/chimera-dev).
-For issues or bugs, please file tickets through [github](https://github.com/intel-hadoop/chimera/issues).

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/cipher/Cipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/Cipher.java b/src/main/java/org/apache/commons/crypto/cipher/Cipher.java
deleted file mode 100644
index 3cbbe3a..0000000
--- a/src/main/java/org/apache/commons/crypto/cipher/Cipher.java
+++ /dev/null
@@ -1,157 +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;
-
-import java.io.Closeable;
-import java.nio.ByteBuffer;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.spec.AlgorithmParameterSpec;
-import java.util.Properties;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.ShortBufferException;
-
-/**
- * The interface of cryptographic cipher for encryption and decryption.
- */
-public interface Cipher extends Closeable {
-
-  /**
-   * A constant representing encrypt mode.  The mode constant to be used
-   * when calling init method of the Cipher.
-   */
-  int ENCRYPT_MODE = javax.crypto.Cipher.ENCRYPT_MODE;
-
-  /**
-   * A constant representing decrypt mode.  The mode constant to be used 
-   * when calling init method of the Cipher.
-   */
-  int DECRYPT_MODE = javax.crypto.Cipher.DECRYPT_MODE;
-
-  /**
-   * Gets the CipherTransformation for this cipher.
-   *
-   * @return the CipherTransformation for this cipher.
-   */
-  CipherTransformation getTransformation();
-
-  /**
-   * Gets the properties for this cipher.
-   * 
-   * @return the properties for this cipher.
-   */
-  Properties getProperties();
-
-  /**
-   * Initializes the cipher with mode, key and iv.
-   * 
-   * @param mode {@link #ENCRYPT_MODE} or {@link #DECRYPT_MODE}
-   * @param key crypto key for the cipher
-   * @param params the algorithm parameters
-   * @throws InvalidKeyException if the given key is inappropriate for
-   * initializing this cipher, or its keysize exceeds the maximum allowable
-   * keysize (as determined from the configured jurisdiction policy files).
-   * @throws InvalidAlgorithmParameterException if the given algorithm
-   * parameters are inappropriate for this cipher, or this cipher requires
-   * algorithm parameters and <code>params</code> is null, or the given
-   * algorithm parameters imply a cryptographic strength that would exceed
-   * the legal limits (as determined from the configured jurisdiction
-   * policy files).
-   */
-  void init(int mode, Key key, AlgorithmParameterSpec params)
-      throws InvalidKeyException, InvalidAlgorithmParameterException;
-
-  /**
-   * Continues a multiple-part encryption/decryption operation. The data
-   * is encrypted or decrypted, depending on how this cipher was initialized.
-   * 
-   * @param inBuffer the input ByteBuffer
-   * @param outBuffer the output ByteBuffer
-   * @return int number of bytes stored in <code>output</code>
-   * @throws ShortBufferException if there is insufficient space
-   * in the output buffer
-   */
-  int update(ByteBuffer inBuffer, ByteBuffer outBuffer)
-      throws ShortBufferException;
-
-  /**
-   * Continues a multiple-part encryption/decryption operation. The data
-   * is encrypted or decrypted, depending on how this cipher was initialized.
-   *
-   * @param input the input byte array
-   * @param inputOffset the offset in input where the input starts
-   * @param inputLen the input length
-   * @param output the byte array for the result
-   * @param outputOffset the offset in output where the result is stored
-   * @return the number of bytes stored in output
-   * @throws ShortBufferException if there is insufficient space in the output byte array
-   */
-  int update(byte[] input, int inputOffset, int inputLen,
-      byte[] output, int outputOffset)
-      throws ShortBufferException;
-
-  /**
-   * Encrypts or decrypts data in a single-part operation, or finishes a
-   * multiple-part operation.
-   * 
-   * @param inBuffer the input ByteBuffer
-   * @param outBuffer the output ByteBuffer
-   * @return int number of bytes stored in <code>output</code>
-   * @throws BadPaddingException if this cipher is in decryption mode,
-   * and (un)padding has been requested, but the decrypted data is not
-   * bounded by the appropriate padding bytes
-   * @throws IllegalBlockSizeException if this cipher is a block cipher,
-   * no padding has been requested (only in encryption mode), and the total
-   * input length of the data processed by this cipher is not a multiple of
-   * block size; or if this encryption algorithm is unable to
-   * process the input data provided.
-   * @throws ShortBufferException if the given output buffer is too small
-   * to hold the result
-   */
-  int doFinal(ByteBuffer inBuffer, ByteBuffer outBuffer)
-      throws ShortBufferException, IllegalBlockSizeException,
-      BadPaddingException;
-
-  /**
-   * Encrypts or decrypts data in a single-part operation, or finishes a
-   * multiple-part operation.
-   *
-   * @param input the input byte array
-   * @param inputOffset the offset in input where the input starts
-   * @param inputLen the input length
-   * @param output the byte array for the result
-   * @param outputOffset the offset in output where the result is stored
-   * @return the number of bytes stored in output
-   * @throws ShortBufferException if the given output byte array is too small
-   * to hold the result
-   * @throws BadPaddingException if this cipher is in decryption mode,
-   * and (un)padding has been requested, but the decrypted data is not
-   * bounded by the appropriate padding bytes
-   * @throws IllegalBlockSizeException if this cipher is a block cipher,
-   * no padding has been requested (only in encryption mode), and the total
-   * input length of the data processed by this cipher is not a multiple of
-   * block size; or if this encryption algorithm is unable to
-   * process the input data provided.
-   */
-  int doFinal(byte[] input, int inputOffset, int inputLen,
-      byte[] output, int outputOffset)
-      throws ShortBufferException, IllegalBlockSizeException, BadPaddingException;
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/cipher/CipherFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CipherFactory.java b/src/main/java/org/apache/commons/crypto/cipher/CipherFactory.java
deleted file mode 100644
index fdaf64c..0000000
--- a/src/main/java/org/apache/commons/crypto/cipher/CipherFactory.java
+++ /dev/null
@@ -1,105 +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;
-
-import java.security.GeneralSecurityException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.commons.crypto.utils.ReflectionUtils;
-import org.apache.commons.crypto.utils.Utils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This is the factory class used for creating cipher class
- */
-public class CipherFactory {
-
-  /** LOG instance for {@CipherFactory} */
-  public final static Logger LOG = LoggerFactory.getLogger(CipherFactory.class);
-
-  private CipherFactory() {}
-
-  /**
-   * Gets a cipher instance for specified algorithm/mode/padding.
-   *
-   * @param props
-   *          the configuration properties
-   * @param transformation
-   *          algorithm/mode/padding
-   * @return Cipher the cipher. Null value will be returned if no
-   *         cipher classes with transformation configured.
-   */
-  public static Cipher getInstance(CipherTransformation transformation,
-      Properties props) throws GeneralSecurityException {
-    List<Class<? extends Cipher>> klasses = getCipherClasses(props);
-    Cipher cipher = null;
-    if (klasses != null) {
-      for (Class<? extends Cipher> klass : klasses) {
-        try {
-          cipher = ReflectionUtils.newInstance(klass, props, transformation);
-          if (cipher != null) {
-            LOG.debug("Using cipher {} for transformation {}.", klass.getName(),
-                transformation.getName());
-            break;
-          }
-        } catch (Exception e) {
-          LOG.error("Cipher {} is not available or transformation {} is not " +
-            "supported.", klass.getName(), transformation.getName());
-        }
-      }
-    }
-
-    return (cipher == null) ? new JceCipher(props, transformation) : cipher;
-  }
-
-  /**
-   * Gets a cipher for algorithm/mode/padding in config value
-   * commons.crypto.cipher.transformation
-   *
-   * @return Cipher the cipher object Null value will be returned if no
-   *         cipher classes with transformation configured.
-   */
-  public static Cipher getInstance(CipherTransformation transformation)
-      throws GeneralSecurityException {
-    return getInstance(transformation, new Properties());
-  }
-
-  // Return OpenSSLCipher if Properties is null or empty by default
-  private static List<Class<? extends Cipher>> getCipherClasses(Properties props) {
-    List<Class<? extends Cipher>> result = new ArrayList<Class<? extends
-        Cipher>>();
-    String cipherClassString = Utils.getCipherClassString(props);
-
-    for (String c : Utils.splitClassNames(cipherClassString, ",")) {
-      try {
-        Class<?> cls = ReflectionUtils.getClassByName(c);
-        result.add(cls.asSubclass(Cipher.class));
-      } catch (ClassCastException e) {
-        LOG.error("Class {} is not a Cipher.", c);
-      } catch (ClassNotFoundException e) {
-        LOG.error("Cipher {} not found.", c);
-      }
-    }
-
-    return result;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/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
new file mode 100644
index 0000000..a47de36
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipher.java
@@ -0,0 +1,157 @@
+/**
+ * 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;
+
+import java.io.Closeable;
+import java.nio.ByteBuffer;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.spec.AlgorithmParameterSpec;
+import java.util.Properties;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.ShortBufferException;
+
+/**
+ * The interface of cryptographic cipher for encryption and decryption.
+ */
+public interface CryptoCipher extends Closeable {
+
+  /**
+   * A constant representing encrypt mode.  The mode constant to be used
+   * when calling init method of the CryptoCipher.
+   */
+  int ENCRYPT_MODE = javax.crypto.Cipher.ENCRYPT_MODE;
+
+  /**
+   * A constant representing decrypt mode.  The mode constant to be used 
+   * when calling init method of the CryptoCipher.
+   */
+  int DECRYPT_MODE = javax.crypto.Cipher.DECRYPT_MODE;
+
+  /**
+   * Gets the CipherTransformation for this cipher.
+   *
+   * @return the CipherTransformation for this cipher.
+   */
+  CipherTransformation getTransformation();
+
+  /**
+   * Gets the properties for this cipher.
+   * 
+   * @return the properties for this cipher.
+   */
+  Properties getProperties();
+
+  /**
+   * Initializes the cipher with mode, key and iv.
+   * 
+   * @param mode {@link #ENCRYPT_MODE} or {@link #DECRYPT_MODE}
+   * @param key crypto key for the cipher
+   * @param params the algorithm parameters
+   * @throws InvalidKeyException if the given key is inappropriate for
+   * initializing this cipher, or its keysize exceeds the maximum allowable
+   * keysize (as determined from the configured jurisdiction policy files).
+   * @throws InvalidAlgorithmParameterException if the given algorithm
+   * parameters are inappropriate for this cipher, or this cipher requires
+   * algorithm parameters and <code>params</code> is null, or the given
+   * algorithm parameters imply a cryptographic strength that would exceed
+   * the legal limits (as determined from the configured jurisdiction
+   * policy files).
+   */
+  void init(int mode, Key key, AlgorithmParameterSpec params)
+      throws InvalidKeyException, InvalidAlgorithmParameterException;
+
+  /**
+   * Continues a multiple-part encryption/decryption operation. The data
+   * is encrypted or decrypted, depending on how this cipher was initialized.
+   * 
+   * @param inBuffer the input ByteBuffer
+   * @param outBuffer the output ByteBuffer
+   * @return int number of bytes stored in <code>output</code>
+   * @throws ShortBufferException if there is insufficient space
+   * in the output buffer
+   */
+  int update(ByteBuffer inBuffer, ByteBuffer outBuffer)
+      throws ShortBufferException;
+
+  /**
+   * Continues a multiple-part encryption/decryption operation. The data
+   * is encrypted or decrypted, depending on how this cipher was initialized.
+   *
+   * @param input the input byte array
+   * @param inputOffset the offset in input where the input starts
+   * @param inputLen the input length
+   * @param output the byte array for the result
+   * @param outputOffset the offset in output where the result is stored
+   * @return the number of bytes stored in output
+   * @throws ShortBufferException if there is insufficient space in the output byte array
+   */
+  int update(byte[] input, int inputOffset, int inputLen,
+      byte[] output, int outputOffset)
+      throws ShortBufferException;
+
+  /**
+   * Encrypts or decrypts data in a single-part operation, or finishes a
+   * multiple-part operation.
+   * 
+   * @param inBuffer the input ByteBuffer
+   * @param outBuffer the output ByteBuffer
+   * @return int number of bytes stored in <code>output</code>
+   * @throws BadPaddingException if this cipher is in decryption mode,
+   * and (un)padding has been requested, but the decrypted data is not
+   * bounded by the appropriate padding bytes
+   * @throws IllegalBlockSizeException if this cipher is a block cipher,
+   * no padding has been requested (only in encryption mode), and the total
+   * input length of the data processed by this cipher is not a multiple of
+   * block size; or if this encryption algorithm is unable to
+   * process the input data provided.
+   * @throws ShortBufferException if the given output buffer is too small
+   * to hold the result
+   */
+  int doFinal(ByteBuffer inBuffer, ByteBuffer outBuffer)
+      throws ShortBufferException, IllegalBlockSizeException,
+      BadPaddingException;
+
+  /**
+   * Encrypts or decrypts data in a single-part operation, or finishes a
+   * multiple-part operation.
+   *
+   * @param input the input byte array
+   * @param inputOffset the offset in input where the input starts
+   * @param inputLen the input length
+   * @param output the byte array for the result
+   * @param outputOffset the offset in output where the result is stored
+   * @return the number of bytes stored in output
+   * @throws ShortBufferException if the given output byte array is too small
+   * to hold the result
+   * @throws BadPaddingException if this cipher is in decryption mode,
+   * and (un)padding has been requested, but the decrypted data is not
+   * bounded by the appropriate padding bytes
+   * @throws IllegalBlockSizeException if this cipher is a block cipher,
+   * no padding has been requested (only in encryption mode), and the total
+   * input length of the data processed by this cipher is not a multiple of
+   * block size; or if this encryption algorithm is unable to
+   * process the input data provided.
+   */
+  int doFinal(byte[] input, int inputOffset, int inputLen,
+      byte[] output, int outputOffset)
+      throws ShortBufferException, IllegalBlockSizeException, BadPaddingException;
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/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
new file mode 100644
index 0000000..20be0cb
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
@@ -0,0 +1,105 @@
+/**
+ * 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;
+
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.crypto.utils.ReflectionUtils;
+import org.apache.commons.crypto.utils.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This is the factory class used for creating cipher class
+ */
+public class CryptoCipherFactory {
+
+  /** LOG instance for {@CipherFactory} */
+  public final static Logger LOG = LoggerFactory.getLogger(CryptoCipherFactory.class);
+
+  private CryptoCipherFactory() {}
+
+  /**
+   * Gets a cipher instance for specified algorithm/mode/padding.
+   *
+   * @param props
+   *          the configuration properties
+   * @param transformation
+   *          algorithm/mode/padding
+   * @return CryptoCipher the cipher. Null value will be returned if no
+   *         cipher classes with transformation configured.
+   */
+  public static CryptoCipher getInstance(CipherTransformation transformation,
+                                         Properties props) throws GeneralSecurityException {
+    List<Class<? extends CryptoCipher>> klasses = getCipherClasses(props);
+    CryptoCipher cipher = null;
+    if (klasses != null) {
+      for (Class<? extends CryptoCipher> klass : klasses) {
+        try {
+          cipher = ReflectionUtils.newInstance(klass, props, transformation);
+          if (cipher != null) {
+            LOG.debug("Using cipher {} for transformation {}.", klass.getName(),
+                transformation.getName());
+            break;
+          }
+        } catch (Exception e) {
+          LOG.error("CryptoCipher {} is not available or transformation {} is not " +
+            "supported.", klass.getName(), transformation.getName());
+        }
+      }
+    }
+
+    return (cipher == null) ? new JceCipher(props, transformation) : cipher;
+  }
+
+  /**
+   * Gets a cipher for algorithm/mode/padding in config value
+   * commons.crypto.cipher.transformation
+   *
+   * @return CryptoCipher the cipher object Null value will be returned if no
+   *         cipher classes with transformation configured.
+   */
+  public static CryptoCipher getInstance(CipherTransformation transformation)
+      throws GeneralSecurityException {
+    return getInstance(transformation, new Properties());
+  }
+
+  // Return OpenSSLCipher if Properties is null or empty by default
+  private static List<Class<? extends CryptoCipher>> getCipherClasses(Properties props) {
+    List<Class<? extends CryptoCipher>> result = new ArrayList<Class<? extends
+            CryptoCipher>>();
+    String cipherClassString = Utils.getCipherClassString(props);
+
+    for (String c : Utils.splitClassNames(cipherClassString, ",")) {
+      try {
+        Class<?> cls = ReflectionUtils.getClassByName(c);
+        result.add(cls.asSubclass(CryptoCipher.class));
+      } catch (ClassCastException e) {
+        LOG.error("Class {} is not a CryptoCipher.", c);
+      } catch (ClassNotFoundException e) {
+        LOG.error("CryptoCipher {} not found.", c);
+      }
+    }
+
+    return result;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/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 873d092..57750c2 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
@@ -32,15 +32,15 @@ import javax.crypto.ShortBufferException;
 import org.apache.commons.crypto.utils.Utils;
 
 /**
- * Implements the {@link org.apache.commons.crypto.cipher.Cipher} using JCE provider.
+ * Implements the {@link org.apache.commons.crypto.cipher.CryptoCipher} using JCE provider.
  */
-public class JceCipher implements Cipher {
+public class JceCipher implements CryptoCipher {
   private final Properties props;
   private final CipherTransformation transformation;
   private final javax.crypto.Cipher cipher;
 
   /**
-   * Constructs a {@link org.apache.commons.crypto.cipher.Cipher} based on JCE
+   * Constructs a {@link org.apache.commons.crypto.cipher.CryptoCipher} based on JCE
    * Cipher {@link javax.crypto.Cipher}.
    * @param props properties for JCE cipher
    * @param transformation transformation for JCE cipher

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/Openssl.java b/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
index 9365859..488438b 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
@@ -87,7 +87,7 @@ public final class Openssl {
       }
     } catch (Throwable t) {
       loadingFailure = t.getMessage();
-      LOG.debug("Failed to load OpenSSL Cipher.", t);
+      LOG.debug("Failed to load OpenSSL CryptoCipher.", t);
     } finally {
       loadingFailureReason = loadingFailure;
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/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 72b247b..e258466 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
@@ -34,15 +34,15 @@ import javax.crypto.spec.IvParameterSpec;
 import org.apache.commons.crypto.utils.Utils;
 
 /**
- * Implements the Cipher using JNI into OpenSSL.
+ * Implements the CryptoCipher using JNI into OpenSSL.
  */
-public class OpensslCipher implements Cipher {
+public class OpensslCipher implements CryptoCipher {
   private final Properties props;
   private final CipherTransformation transformation;
   private final Openssl cipher;
 
   /**
-   * Constructs a {@link org.apache.commons.crypto.cipher.Cipher} using JNI into OpenSSL
+   * Constructs a {@link org.apache.commons.crypto.cipher.CryptoCipher} using JNI into OpenSSL
    * 
    * @param props properties for OpenSSL cipher
    * @param transformation transformation for OpenSSL cipher

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/cipher/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/package-info.java b/src/main/java/org/apache/commons/crypto/cipher/package-info.java
index c650b57..0da563f 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/package-info.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/package-info.java
@@ -17,6 +17,6 @@
  */
 
 /**
- * Cipher classes
+ * CryptoCipher classes
  */
 package org.apache.commons.crypto.cipher;

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java b/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
index ae07758..989cee3 100644
--- a/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
+++ b/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
@@ -17,7 +17,9 @@
  */
 package org.apache.commons.crypto.conf;
 
+import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.cipher.OpensslCipher;
+import org.apache.commons.crypto.random.CryptoRandom;
 
 /**
  * The ConfigurationKeys contains Configuration keys and default values.
@@ -41,7 +43,7 @@ public class ConfigurationKeys {
    * "org.apache.commons.crypto.cipher.JceCipher" and "org.apache.commons.crypto.cipher.OpensslCipher".
    * And it takes a common separated list.
    * The "org.apache.commons.crypto.cipher.JceCipher" use jce provider to
-   * implement {@link org.apache.commons.crypto.cipher.Cipher} and
+   * implement {@link org.apache.commons.crypto.cipher.CryptoCipher} and
    * the "org.apache.commons.crypto.cipher.OpensslCipher" use jni into openssl to implement.
    * Note that for each value,the first value which can be created without exception
    * will be used (priority by order).
@@ -89,11 +91,11 @@ public class ConfigurationKeys {
   /**
    * The configuration key of the implementation class for secure random.
    * The values of COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY can be
-   * "org.apache.commons.crypto.random.JavaSecureRandom" and "org.apache.commons.crypto.random.OpensslSecureRandom".
+   * "org.apache.commons.crypto.random.JavaCryptoRandom" and "org.apache.commons.crypto.random.OpensslCryptoRandom".
    * And it takes a common separated list.
-   * The "org.apache.commons.crypto.random.JavaSecureRandom" use java to
-   * implement {@link org.apache.commons.crypto.random.SecureRandom} and
-   * the "org.apache.commons.crypto.random.OpensslSecureRandom" use jni into openssl to implement.
+   * The "org.apache.commons.crypto.random.JavaCryptoRandom" use java to
+   * implement {@link CryptoRandom} and
+   * the "org.apache.commons.crypto.random.OpensslCryptoRandom" use jni into openssl to implement.
    * Note that for each value,the first value which can be created without exception
    * will be used (priority by order).
    */

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/CryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandom.java
new file mode 100644
index 0000000..8194a9b
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandom.java
@@ -0,0 +1,36 @@
+/**
+ * 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.random;
+
+import java.io.Closeable;
+
+/**
+ * The interface for CryptoRandom.
+ */
+public interface CryptoRandom extends Closeable {
+
+  /**
+   * Generates random bytes and places them into a user-supplied
+   * byte array.  The number of random bytes produced is equal to
+   * the length of the byte array.
+   *
+   * @param bytes the byte array to fill with random bytes
+   */
+  void nextBytes(byte[] bytes);
+
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
new file mode 100644
index 0000000..8c9fd35
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
@@ -0,0 +1,76 @@
+/**
+ * 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.random;
+
+import java.security.GeneralSecurityException;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.crypto.utils.Utils;
+import org.apache.commons.crypto.utils.ReflectionUtils;
+
+import static org.apache.commons.crypto.conf.ConfigurationKeys
+    .COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY;
+
+/**
+ * This is the factory class used for {@link CryptoRandom}.
+ */
+public class CryptoRandomFactory {
+  public final static Logger LOG = LoggerFactory
+      .getLogger(CryptoRandomFactory.class);
+
+  private CryptoRandomFactory() {}
+
+  /**
+   * Gets a CryptoRandom instance for specified props.
+   *
+   * @param props the configuration properties.
+   * @return CryptoRandom the cryptoRandom object.Null value will be returned if no CryptoRandom
+   *         classes with props.
+   * @throws GeneralSecurityException if fail to create the {@link CryptoRandom}.
+   */
+  public static CryptoRandom getCryptoRandom(Properties props) throws GeneralSecurityException {
+    String cryptoRandomClasses = props.getProperty(
+        COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
+    if (cryptoRandomClasses == null) {
+      cryptoRandomClasses = System.getProperty(
+          COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
+    }
+
+    CryptoRandom random = null;
+    if (cryptoRandomClasses != null) {
+      for (String klassName : Utils.splitClassNames(cryptoRandomClasses, ",")) {
+        try {
+          final Class<?> klass = ReflectionUtils.getClassByName(klassName);
+          random = (CryptoRandom) ReflectionUtils.newInstance(klass, props);
+          if (random != null) {
+            break;
+          }
+        } catch (ClassCastException e) {
+          LOG.error("Class {} is not a CryptoCipher.", klassName);
+        } catch (ClassNotFoundException e) {
+          LOG.error("CryptoCipher {} not found.", klassName);
+        }
+      }
+    }
+
+    return (random == null) ? new JavaCryptoRandom(props) : random;
+  }
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
new file mode 100644
index 0000000..aff8f39
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
@@ -0,0 +1,76 @@
+/**
+ * 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.random;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.crypto.conf.ConfigurationKeys;
+
+/**
+ * A CryptoRandom of Java implementation.
+ */
+public class JavaCryptoRandom implements CryptoRandom {
+  private static final Log LOG =
+      LogFactory.getLog(JavaCryptoRandom.class.getName());
+
+  private java.security.SecureRandom instance;
+
+  /**
+   * Constructs a {@link org.apache.commons.crypto.random.JavaCryptoRandom}.
+   *
+   * @param properties the configuration properties.
+   * @throws NoSuchAlgorithmException if no Provider supports a SecureRandomSpi implementation for
+   *         the specified algorithm.
+   */
+  public JavaCryptoRandom(Properties properties) throws NoSuchAlgorithmException {
+    try {
+      instance = java.security.SecureRandom
+          .getInstance(properties.getProperty(
+              ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_KEY,
+              ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_DEFAULT));
+    } catch (NoSuchAlgorithmException e) {
+      LOG.error("Failed to create java secure random due to error: " + e);
+      throw e;
+    }
+  }
+
+  /**
+   * Overrides {@link java.lang.AutoCloseable#close()}.
+   * For{@link JavaCryptoRandom}, we don't need to recycle resource.
+   */
+  @Override
+  public void close() {
+    // do nothing
+  }
+
+  /**
+   * Overrides {@link org.apache.commons.crypto.random.CryptoRandom#nextBytes(byte[])}.
+   * Generates random bytes and places them into a user-supplied byte array.
+   * The number of random bytes produced is equal to the length of the byte array.
+   *
+   * @param bytes the array to be filled in with random bytes.
+   */
+  @Override
+  public void nextBytes(byte[] bytes) {
+    instance.nextBytes(bytes);
+  }
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/JavaSecureRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/JavaSecureRandom.java b/src/main/java/org/apache/commons/crypto/random/JavaSecureRandom.java
deleted file mode 100644
index 60b8448..0000000
--- a/src/main/java/org/apache/commons/crypto/random/JavaSecureRandom.java
+++ /dev/null
@@ -1,76 +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.random;
-
-import java.security.NoSuchAlgorithmException;
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.commons.crypto.conf.ConfigurationKeys;
-
-/**
- * A SecureRandom of Java implementation.
- */
-public class JavaSecureRandom implements SecureRandom {
-  private static final Log LOG =
-      LogFactory.getLog(JavaSecureRandom.class.getName());
-
-  private java.security.SecureRandom instance;
-
-  /**
-   * Constructs a {@link org.apache.commons.crypto.random.JavaSecureRandom}.
-   *
-   * @param properties the configuration properties.
-   * @throws NoSuchAlgorithmException if no Provider supports a SecureRandomSpi implementation for
-   *         the specified algorithm.
-   */
-  public JavaSecureRandom(Properties properties) throws NoSuchAlgorithmException {
-    try {
-      instance = java.security.SecureRandom
-          .getInstance(properties.getProperty(
-              ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_KEY,
-              ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_DEFAULT));
-    } catch (NoSuchAlgorithmException e) {
-      LOG.error("Failed to create java secure random due to error: " + e);
-      throw e;
-    }
-  }
-
-  /**
-   * Overrides {@link java.lang.AutoCloseable#close()}.
-   * For{@link JavaSecureRandom}, we don't need to recycle resource.
-   */
-  @Override
-  public void close() {
-    // do nothing
-  }
-
-  /**
-   * Overrides {@link org.apache.commons.crypto.random.SecureRandom#nextBytes(byte[])}.
-   * Generates random bytes and places them into a user-supplied byte array.
-   * The number of random bytes produced is equal to the length of the byte array.
-   *
-   * @param bytes the array to be filled in with random bytes.
-   */
-  @Override
-  public void nextBytes(byte[] bytes) {
-    instance.nextBytes(bytes);
-  }
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandom.java
new file mode 100644
index 0000000..406ddef
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandom.java
@@ -0,0 +1,143 @@
+/**
+ * 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.random;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.Properties;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.crypto.utils.NativeCodeLoader;
+import org.apache.commons.crypto.utils.Utils;
+
+/**
+ * OpenSSL secure random using JNI.
+ * This implementation is thread-safe.
+ * <p/>
+ *
+ * If using an Intel chipset with RDRAND, the high-performance hardware
+ * random number generator will be used and it's much faster than
+ * {@link java.security.SecureRandom}. If RDRAND is unavailable, default
+ * OpenSSL secure random generator will be used. It's still faster
+ * and can generate strong random bytes.
+ * <p/>
+ * @see https://wiki.openssl.org/index.php/Random_Numbers
+ * @see http://en.wikipedia.org/wiki/RdRand
+ */
+public class OpensslCryptoRandom extends Random implements CryptoRandom {
+  private static final long serialVersionUID = -7828193502768789584L;
+  private static final Log LOG =
+      LogFactory.getLog(OpensslCryptoRandom.class.getName());
+
+  /** If native CryptoRandom unavailable, use java SecureRandom */
+  private JavaCryptoRandom fallback = null;
+  private static boolean nativeEnabled = false;
+  static {
+    if (NativeCodeLoader.isNativeCodeLoaded()) {
+      try {
+        OpensslCryptoRandomNative.initSR();
+        nativeEnabled = true;
+      } catch (Throwable t) {
+        LOG.error("Failed to load Openssl CryptoRandom", t);
+      }
+    }
+  }
+
+  /**
+   * Judges whether loading native library successfully.
+   *
+   * @return true if loading library successfully.
+   */
+  public static boolean isNativeCodeLoaded() {
+    return nativeEnabled;
+  }
+
+  /**
+   * Constructs a {@link org.apache.commons.crypto.random.OpensslCryptoRandom}.
+   *
+   * @param props the configuration properties.
+   * @throws NoSuchAlgorithmException if no Provider supports a SecureRandomSpi implementation for
+   *         the specified algorithm.
+   */
+  public OpensslCryptoRandom(Properties props) throws NoSuchAlgorithmException {
+    if (!nativeEnabled) {
+      fallback = new JavaCryptoRandom(props);
+    }
+  }
+
+  /**
+   * Generates a user-specified number of random bytes.
+   * It's thread-safe.
+   *
+   * @param bytes the array to be filled in with random bytes.
+   */
+  @Override
+  public void nextBytes(byte[] bytes) {
+    if (!nativeEnabled || !OpensslCryptoRandomNative.nextRandBytes(bytes)) {
+      fallback.nextBytes(bytes);
+    }
+  }
+
+  /**
+   * Overrides {@link OpensslCryptoRandom}.
+   * For {@link OpensslCryptoRandom}, we don't need to set seed.
+   *
+   * @param seed the initial seed.
+   */
+  @Override
+  public void setSeed(long seed) {
+    // Self-seeding.
+  }
+
+  /**
+   * Overrides {@link java.util.Random# next()}. Generates an integer
+   * containing the user-specified number of random
+   * bits(right justified, with leading zeros).
+   *
+   * @param numBits number of random bits to be generated, where
+   * 0 <= <code>numBits</code> <= 32.
+   * @return int an <code>int</code> containing the user-specified number
+   * of random bits (right justified, with leading zeros).
+   */
+  @Override
+  final protected int next(int numBits) {
+    Utils.checkArgument(numBits >= 0 && numBits <= 32);
+    int numBytes = (numBits + 7) / 8;
+    byte b[] = new byte[numBytes];
+    int next = 0;
+
+    nextBytes(b);
+    for (int i = 0; i < numBytes; i++) {
+      next = (next << 8) + (b[i] & 0xFF);
+    }
+
+    return next >>> (numBytes * 8 - numBits);
+  }
+
+  /**
+   * Overrides {@link java.lang.AutoCloseable#close()}. Closes openssl context if native enabled.
+   */
+  @Override
+  public void close() {
+    if (!nativeEnabled && fallback !=null) {
+      fallback.close();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandomNative.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandomNative.java b/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandomNative.java
new file mode 100644
index 0000000..c72cad6
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/random/OpensslCryptoRandomNative.java
@@ -0,0 +1,43 @@
+/**
+ * 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.random;
+
+/**
+ * JNI interface of {@link CryptoRandom} implementation.
+ * The native method in this class is defined in
+ * OpensslCryptoRandomNative.h(genereted by javah).
+ */
+public class OpensslCryptoRandomNative {
+
+  private OpensslCryptoRandomNative() {}
+
+  /**
+   * Declares a native method to initialize SR.
+   */
+  public native static void initSR();
+
+  /**
+   * Judges whether use {@link OpensslCryptoRandomNative} to
+   * generate the user-specified number of random bits.
+   *
+   * @param bytes the array to be filled in with random bytes.
+   * @return true if use {@link OpensslCryptoRandomNative} to
+   * generate the user-specified number of random bits.
+   */
+  public native static boolean nextRandBytes(byte[] bytes); 
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandom.java b/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandom.java
deleted file mode 100644
index 2ad3244..0000000
--- a/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandom.java
+++ /dev/null
@@ -1,143 +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.random;
-
-import java.security.NoSuchAlgorithmException;
-import java.util.Properties;
-import java.util.Random;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.commons.crypto.utils.NativeCodeLoader;
-import org.apache.commons.crypto.utils.Utils;
-
-/**
- * OpenSSL secure random using JNI.
- * This implementation is thread-safe.
- * <p/>
- *
- * If using an Intel chipset with RDRAND, the high-performance hardware
- * random number generator will be used and it's much faster than
- * {@link java.security.SecureRandom}. If RDRAND is unavailable, default
- * OpenSSL secure random generator will be used. It's still faster
- * and can generate strong random bytes.
- * <p/>
- * @see https://wiki.openssl.org/index.php/Random_Numbers
- * @see http://en.wikipedia.org/wiki/RdRand
- */
-public class OpensslSecureRandom extends Random implements SecureRandom {
-  private static final long serialVersionUID = -7828193502768789584L;
-  private static final Log LOG =
-      LogFactory.getLog(OpensslSecureRandom.class.getName());
-
-  /** If native SecureRandom unavailable, use java SecureRandom */
-  private JavaSecureRandom fallback = null;
-  private static boolean nativeEnabled = false;
-  static {
-    if (NativeCodeLoader.isNativeCodeLoaded()) {
-      try {
-        OpensslSecureRandomNative.initSR();
-        nativeEnabled = true;
-      } catch (Throwable t) {
-        LOG.error("Failed to load Openssl SecureRandom", t);
-      }
-    }
-  }
-
-  /**
-   * Judges whether loading native library successfully.
-   *
-   * @return true if loading library successfully.
-   */
-  public static boolean isNativeCodeLoaded() {
-    return nativeEnabled;
-  }
-
-  /**
-   * Constructs a {@link org.apache.commons.crypto.random.OpensslSecureRandom}.
-   *
-   * @param props the configuration properties.
-   * @throws NoSuchAlgorithmException if no Provider supports a SecureRandomSpi implementation for
-   *         the specified algorithm.
-   */
-  public OpensslSecureRandom(Properties props) throws NoSuchAlgorithmException {
-    if (!nativeEnabled) {
-      fallback = new JavaSecureRandom(props);
-    }
-  }
-
-  /**
-   * Generates a user-specified number of random bytes.
-   * It's thread-safe.
-   *
-   * @param bytes the array to be filled in with random bytes.
-   */
-  @Override
-  public void nextBytes(byte[] bytes) {
-    if (!nativeEnabled || !OpensslSecureRandomNative.nextRandBytes(bytes)) {
-      fallback.nextBytes(bytes);
-    }
-  }
-
-  /**
-   * Overrides {@link OpensslSecureRandom}.
-   * For {@link OpensslSecureRandom}, we don't need to set seed.
-   *
-   * @param seed the initial seed.
-   */
-  @Override
-  public void setSeed(long seed) {
-    // Self-seeding.
-  }
-
-  /**
-   * Overrides {@link java.util.Random# next()}. Generates an integer
-   * containing the user-specified number of random
-   * bits(right justified, with leading zeros).
-   *
-   * @param numBits number of random bits to be generated, where
-   * 0 <= <code>numBits</code> <= 32.
-   * @return int an <code>int</code> containing the user-specified number
-   * of random bits (right justified, with leading zeros).
-   */
-  @Override
-  final protected int next(int numBits) {
-    Utils.checkArgument(numBits >= 0 && numBits <= 32);
-    int numBytes = (numBits + 7) / 8;
-    byte b[] = new byte[numBytes];
-    int next = 0;
-
-    nextBytes(b);
-    for (int i = 0; i < numBytes; i++) {
-      next = (next << 8) + (b[i] & 0xFF);
-    }
-
-    return next >>> (numBytes * 8 - numBits);
-  }
-
-  /**
-   * Overrides {@link java.lang.AutoCloseable#close()}. Closes openssl context if native enabled.
-   */
-  @Override
-  public void close() {
-    if (!nativeEnabled && fallback !=null) {
-      fallback.close();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandomNative.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandomNative.java b/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandomNative.java
deleted file mode 100644
index c36083f..0000000
--- a/src/main/java/org/apache/commons/crypto/random/OpensslSecureRandomNative.java
+++ /dev/null
@@ -1,43 +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.random;
-
-/**
- * JNI interface of {@link SecureRandom} implementation.
- * The native method in this class is defined in
- * OpensslSecureRandomNative.h(genereted by javah).
- */
-public class OpensslSecureRandomNative {
-
-  private OpensslSecureRandomNative() {}
-
-  /**
-   * Declares a native method to initialize SR.
-   */
-  public native static void initSR();
-
-  /**
-   * Judges whether use {@link OpensslSecureRandomNative} to
-   * generate the user-specified number of random bits.
-   *
-   * @param bytes the array to be filled in with random bytes.
-   * @return true if use {@link OpensslSecureRandomNative} to
-   * generate the user-specified number of random bits.
-   */
-  public native static boolean nextRandBytes(byte[] bytes); 
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
new file mode 100644
index 0000000..4e6c063
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
@@ -0,0 +1,133 @@
+/**
+ * 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.random;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Random;
+
+import org.apache.commons.crypto.utils.IOUtils;
+import org.apache.commons.crypto.utils.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A Random implementation that uses random bytes sourced from the
+ * operating system.
+ */
+public class OsCryptoRandom extends Random implements CryptoRandom {
+  public static final Log LOG = LogFactory.getLog(OsCryptoRandom.class);
+  
+  private static final long serialVersionUID = 6391500337172057900L;
+
+  private final int RESERVOIR_LENGTH = 8192;
+
+  private String randomDevPath;
+
+  private transient FileInputStream stream;
+
+  private final byte[] reservoir = new byte[RESERVOIR_LENGTH];
+
+  private int pos = reservoir.length;
+
+  private void fillReservoir(int min) {
+    if (pos >= reservoir.length - min) {
+      try {
+        IOUtils.readFully(stream, reservoir, 0, reservoir.length);
+      } catch (IOException e) {
+        throw new RuntimeException("failed to fill reservoir", e);
+      }
+      pos = 0;
+    }
+  }
+
+  /**
+   * Constructs a {@link org.apache.commons.crypto.random.OsCryptoRandom}.
+   *
+   * @param props the configuration properties.
+   */
+  public OsCryptoRandom(Properties props) {
+    randomDevPath = Utils.getRandomDevPath(props);
+    File randomDevFile = new File(randomDevPath);
+
+    try {
+      close();
+      this.stream = new FileInputStream(randomDevFile);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+
+    try {
+      fillReservoir(0);
+    } catch (RuntimeException e) {
+      close();
+      throw e;
+    }
+  }
+
+  /**
+   * Overrides {@link org.apache.commons.crypto.random.CryptoRandom#nextBytes(byte[])}.
+   * Generates random bytes and places them into a user-supplied byte array.
+   * The number of random bytes produced is equal to the length of the byte array.
+   *
+   * @param bytes the array to be filled in with random bytes.
+   */
+  @Override
+  synchronized public void nextBytes(byte[] bytes) {
+    int off = 0;
+    int n = 0;
+    while (off < bytes.length) {
+      fillReservoir(0);
+      n = Math.min(bytes.length - off, reservoir.length - pos);
+      System.arraycopy(reservoir, pos, bytes, off, n);
+      off += n;
+      pos += n;
+    }
+  }
+
+  /**
+   * Overrides {@link java.util.Random# next()}. Generates the next pseudorandom number.
+   * Subclasses should override this, as this is used by all other methods.
+   *
+   * @param  nbits random bits.
+   * @return the next pseudorandom value from this random number
+   *         generator's sequence.
+   */
+  @Override
+  synchronized protected int next(int nbits) {
+    fillReservoir(4);
+    int n = 0;
+    for (int i = 0; i < 4; i++) {
+      n = ((n << 8) | (reservoir[pos++] & 0xff));
+    }
+    return n & (0xffffffff >> (32 - nbits));
+  }
+
+  /**
+   * Overrides {@link java.lang.AutoCloseable#close()}. Closes the OS stream.
+   */
+  @Override
+  synchronized public void close() {
+    if (stream != null) {
+      IOUtils.cleanup(LOG, stream);
+      stream = null;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/OsSecureRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OsSecureRandom.java b/src/main/java/org/apache/commons/crypto/random/OsSecureRandom.java
deleted file mode 100644
index 916ad10..0000000
--- a/src/main/java/org/apache/commons/crypto/random/OsSecureRandom.java
+++ /dev/null
@@ -1,133 +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.random;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.Random;
-
-import org.apache.commons.crypto.utils.IOUtils;
-import org.apache.commons.crypto.utils.Utils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * A Random implementation that uses random bytes sourced from the
- * operating system.
- */
-public class OsSecureRandom extends Random implements SecureRandom {
-  public static final Log LOG = LogFactory.getLog(OsSecureRandom.class);
-  
-  private static final long serialVersionUID = 6391500337172057900L;
-
-  private final int RESERVOIR_LENGTH = 8192;
-
-  private String randomDevPath;
-
-  private transient FileInputStream stream;
-
-  private final byte[] reservoir = new byte[RESERVOIR_LENGTH];
-
-  private int pos = reservoir.length;
-
-  private void fillReservoir(int min) {
-    if (pos >= reservoir.length - min) {
-      try {
-        IOUtils.readFully(stream, reservoir, 0, reservoir.length);
-      } catch (IOException e) {
-        throw new RuntimeException("failed to fill reservoir", e);
-      }
-      pos = 0;
-    }
-  }
-
-  /**
-   * Constructs a {@link org.apache.commons.crypto.random.OsSecureRandom}.
-   *
-   * @param props the configuration properties.
-   */
-  public OsSecureRandom(Properties props) {
-    randomDevPath = Utils.getRandomDevPath(props);
-    File randomDevFile = new File(randomDevPath);
-
-    try {
-      close();
-      this.stream = new FileInputStream(randomDevFile);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-
-    try {
-      fillReservoir(0);
-    } catch (RuntimeException e) {
-      close();
-      throw e;
-    }
-  }
-
-  /**
-   * Overrides {@link org.apache.commons.crypto.random.SecureRandom#nextBytes(byte[])}.
-   * Generates random bytes and places them into a user-supplied byte array.
-   * The number of random bytes produced is equal to the length of the byte array.
-   *
-   * @param bytes the array to be filled in with random bytes.
-   */
-  @Override
-  synchronized public void nextBytes(byte[] bytes) {
-    int off = 0;
-    int n = 0;
-    while (off < bytes.length) {
-      fillReservoir(0);
-      n = Math.min(bytes.length - off, reservoir.length - pos);
-      System.arraycopy(reservoir, pos, bytes, off, n);
-      off += n;
-      pos += n;
-    }
-  }
-
-  /**
-   * Overrides {@link java.util.Random# next()}. Generates the next pseudorandom number.
-   * Subclasses should override this, as this is used by all other methods.
-   *
-   * @param  nbits random bits.
-   * @return the next pseudorandom value from this random number
-   *         generator's sequence.
-   */
-  @Override
-  synchronized protected int next(int nbits) {
-    fillReservoir(4);
-    int n = 0;
-    for (int i = 0; i < 4; i++) {
-      n = ((n << 8) | (reservoir[pos++] & 0xff));
-    }
-    return n & (0xffffffff >> (32 - nbits));
-  }
-
-  /**
-   * Overrides {@link java.lang.AutoCloseable#close()}. Closes the OS stream.
-   */
-  @Override
-  synchronized public void close() {
-    if (stream != null) {
-      IOUtils.cleanup(LOG, stream);
-      stream = null;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/SecureRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/SecureRandom.java b/src/main/java/org/apache/commons/crypto/random/SecureRandom.java
deleted file mode 100644
index 69c5559..0000000
--- a/src/main/java/org/apache/commons/crypto/random/SecureRandom.java
+++ /dev/null
@@ -1,36 +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.random;
-
-import java.io.Closeable;
-
-/**
- * The interface for SecureRandom.
- */
-public interface SecureRandom extends Closeable {
-
-  /**
-   * Generates random bytes and places them into a user-supplied
-   * byte array.  The number of random bytes produced is equal to
-   * the length of the byte array.
-   *
-   * @param bytes the byte array to fill with random bytes
-   */
-  void nextBytes(byte[] bytes);
-
-}

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/ea89d802/src/main/java/org/apache/commons/crypto/random/SecureRandomFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/SecureRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/SecureRandomFactory.java
deleted file mode 100644
index 3e42857..0000000
--- a/src/main/java/org/apache/commons/crypto/random/SecureRandomFactory.java
+++ /dev/null
@@ -1,76 +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.random;
-
-import java.security.GeneralSecurityException;
-import java.util.Properties;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.crypto.utils.Utils;
-import org.apache.commons.crypto.utils.ReflectionUtils;
-
-import static org.apache.commons.crypto.conf.ConfigurationKeys
-    .COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY;
-
-/**
- * This is the factory class used for {@link SecureRandom}.
- */
-public class SecureRandomFactory {
-  public final static Logger LOG = LoggerFactory
-      .getLogger(SecureRandomFactory.class);
-
-  private SecureRandomFactory() {}
-
-  /**
-   * Gets a SecureRandom instance for specified props.
-   *
-   * @param props the configuration properties.
-   * @return SecureRandom the secureRandom object.Null value will be returned if no SecureRandom
-   *         classes with props.
-   * @throws GeneralSecurityException if fail to create the {@link SecureRandom}.
-   */
-  public static SecureRandom getSecureRandom(Properties props) throws GeneralSecurityException {
-    String secureRandomClasses = props.getProperty(
-        COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
-    if (secureRandomClasses == null) {
-      secureRandomClasses = System.getProperty(
-          COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
-    }
-
-    SecureRandom random = null;
-    if (secureRandomClasses != null) {
-      for (String klassName : Utils.splitClassNames(secureRandomClasses, ",")) {
-        try {
-          final Class<?> klass = ReflectionUtils.getClassByName(klassName);
-          random = (SecureRandom) ReflectionUtils.newInstance(klass, props);
-          if (random != null) {
-            break;
-          }
-        } catch (ClassCastException e) {
-          LOG.error("Class {} is not a Cipher.", klassName);
-        } catch (ClassNotFoundException e) {
-          LOG.error("Cipher {} not found.", klassName);
-        }
-      }
-    }
-
-    return (random == null) ? new JavaSecureRandom(props) : random;
-  }
-}