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/07/10 12:39:37 UTC

commons-crypto git commit: CRYPTO-111 Include minimal main class to show that the code is working

Repository: commons-crypto
Updated Branches:
  refs/heads/master 4ac4fedf1 -> 403c632fb


CRYPTO-111 Include minimal main class to show that the code is working

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

Branch: refs/heads/master
Commit: 403c632fb9068ee72a1cc2d5be13f837a85f3b9c
Parents: 4ac4fed
Author: Sebb <se...@apache.org>
Authored: Sun Jul 10 13:39:33 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Sun Jul 10 13:39:33 2016 +0100

----------------------------------------------------------------------
 pom.xml                                         | 12 ++++++++++
 .../java/org/apache/commons/crypto/Crypto.java  | 25 ++++++++++++++++++++
 2 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/403c632f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d6829fa..fc27e2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -440,6 +440,18 @@ The following provides more details on the included cryptographic software:
     </pluginManagement>
     <plugins>
       <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <!-- Helper application -->
+              <Main-Class>org.apache.commons.crypto.Crypto</Main-Class>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
         <artifactId>maven-resources-plugin</artifactId>
         <version>2.7</version>
         <executions>

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/403c632f/src/main/java/org/apache/commons/crypto/Crypto.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/Crypto.java b/src/main/java/org/apache/commons/crypto/Crypto.java
index d913878..47575d4 100644
--- a/src/main/java/org/apache/commons/crypto/Crypto.java
+++ b/src/main/java/org/apache/commons/crypto/Crypto.java
@@ -20,8 +20,12 @@ package org.apache.commons.crypto;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.security.GeneralSecurityException;
 import java.util.Properties;
 
+import org.apache.commons.crypto.cipher.CryptoCipherFactory;
+import org.apache.commons.crypto.random.CryptoRandomFactory;
+
 /**
  * Provides diagnostic information about Commons Crypto and keys for native class loading
  */
@@ -113,4 +117,25 @@ public final class Crypto {
         return ComponentPropertiesHolder.PROPERTIES.getProperty("NAME");
     }
 
+    public static void main(String args[]) throws Exception {
+        System.out.println(getComponentName() + " " + getComponentVersion());
+        if (isNativeCodeLoaded()) {
+            System.out.println("Native code loaded OK, version: TBA"); // TODO get VERSION from native code
+            {
+                Properties props = new Properties();
+                props.setProperty(CryptoRandomFactory.CLASSES_KEY, CryptoRandomFactory.RandomProvider.OPENSSL.getClassName());
+                CryptoRandomFactory.getCryptoRandom(props);
+                System.out.println("Random instance created OK");
+            }
+            System.out.println("OpenSSL library loaded OK, version: TBA"); // TODO get SSLeay() etc. from library
+            {
+                Properties props = new Properties();
+                props.setProperty(CryptoCipherFactory.CLASSES_KEY, CryptoCipherFactory.CipherProvider.OPENSSL.getClassName());
+                CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props);
+                System.out.println("Cipher instance created OK");
+            }
+        } else {
+            System.out.println("Native load failed: " + getLoadingError());            
+        }
+    }
 }