You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2016/06/24 09:41:08 UTC
commons-crypto git commit: Docn
Repository: commons-crypto
Updated Branches:
refs/heads/master 49a264718 -> 06b498647
Docn
Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/06b49864
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/06b49864
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/06b49864
Branch: refs/heads/master
Commit: 06b49864735720bf1e61c359cedcc50eff9b8754
Parents: 49a2647
Author: Sebb <se...@apache.org>
Authored: Fri Jun 24 10:41:05 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Fri Jun 24 10:41:05 2016 +0100
----------------------------------------------------------------------
.../apache/commons/crypto/examples/RandomExample.java | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/06b49864/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/RandomExample.java b/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
index 7e0c220..4e0f6a4 100644
--- a/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
@@ -26,6 +26,9 @@ import org.apache.commons.crypto.conf.ConfigurationKeys;
import org.apache.commons.crypto.random.CryptoRandom;
import org.apache.commons.crypto.random.CryptoRandomFactory;
+/**
+ * Example showing use of the CryptoRandom API
+ */
public class RandomExample {
/**
@@ -38,21 +41,26 @@ public class RandomExample {
public static void main(String []args) throws GeneralSecurityException, IOException {
//Constructs a byte array to store random data.
byte[] key = new byte[16];
- byte[] iv = new byte[16];
+ byte[] iv = new byte[32];
+
Properties properties = new Properties();
properties.put(ConfigurationKeys.SECURE_RANDOM_CLASSES_KEY,
"org.apache.commons.crypto.random.OpensslCryptoRandom"); // TODO replace with alias
+
//Gets the 'CryptoRandom' instance.
CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties);
+
+ // Show the actual class (may be different from the one requested)
System.out.println(random.getClass().getCanonicalName());
- //Generates random bytes and places them into the byte array.
+ // Generate random bytes and places them into the byte arrays.
random.nextBytes(key);
random.nextBytes(iv);
+
//Closes the CryptoRandom.
random.close();
- // Show the output
+ // Show the generated output
System.out.println(Arrays.toString(key));
System.out.println(Arrays.toString(iv));
}