Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 440B8200AE4 for ; Fri, 24 Jun 2016 11:41:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 42B8C160A5A; Fri, 24 Jun 2016 09:41:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8B2B2160A38 for ; Fri, 24 Jun 2016 11:41:09 +0200 (CEST) Received: (qmail 75917 invoked by uid 500); 24 Jun 2016 09:41:08 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 75908 invoked by uid 99); 24 Jun 2016 09:41:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jun 2016 09:41:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 575CEE049D; Fri, 24 Jun 2016 09:41:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sebb@apache.org To: commits@commons.apache.org Message-Id: <18a051d2456040669c5f00312009a216@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: commons-crypto git commit: Docn Date: Fri, 24 Jun 2016 09:41:08 +0000 (UTC) archived-at: Fri, 24 Jun 2016 09:41:10 -0000 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 Authored: Fri Jun 24 10:41:05 2016 +0100 Committer: Sebb 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)); }