You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by gk...@apache.org on 2020/07/01 10:26:33 UTC

svn commit: r1879399 - in /turbine/fulcrum/trunk/yaafi-crypto: ./ src/changes/ src/java/org/apache/fulcrum/jce/crypto/ src/java/org/apache/fulcrum/jce/crypto/algo/ src/java/org/apache/fulcrum/jce/crypto/cli/ src/java/org/apache/fulcrum/jce/crypto/exten...

Author: gk
Date: Wed Jul  1 10:26:32 2020
New Revision: 1879399

URL: http://svn.apache.org/viewvc?rev=1879399&view=rev
Log:
- removed duplicate method in CryptoParametersJ8 and (almost) duplicate class CryptoStreamFactoryJ8Impl (as in CryptoStreamPBEImpl)
- cleanup java code
- remove hard coded SH1PRNG, replacing it with SecureRandom.getInstanceStrong in CryptoStreamFactoryJ8Template
- fixing javadoc, xdoc
- updating to testcontainer 9-SNAPSHOT (fixing eclipse ide integration issue)
- update svn:ignore prop


Removed:
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8Impl.java
Modified:
    turbine/fulcrum/trunk/yaafi-crypto/   (props changed)
    turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt
    turbine/fulcrum/trunk/yaafi-crypto/pom.xml
    turbine/fulcrum/trunk/yaafi-crypto/src/changes/changes.xml
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamGCMImpl.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamPBEImpl.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoParametersJ8.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8Template.java
    turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8.java
    turbine/fulcrum/trunk/yaafi-crypto/src/test/log4j2.xml
    turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8ParameterizedTest.java
    turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8Test.java
    turbine/fulcrum/trunk/yaafi-crypto/xdocs/downloads.xml

Propchange: turbine/fulcrum/trunk/yaafi-crypto/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Jul  1 10:26:32 2020
@@ -1,7 +1,13 @@
 target
-.externalToolBuilders
-.settings
+*~
+*.ipr
+*.iws
+*.log
 .classpath
 .project
-maven-eclipse.xml
-fulcrum-yaafi-crypto.iml
+.idea
+.settings
+*.iml
+
+*.ser
+junit*.properties

Modified: turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/NOTICE.txt Wed Jul  1 10:26:32 2020
@@ -1,5 +1,5 @@
 Turbine Fulcrum YAAFI-Cypto Component
-Copyright 2002-2019 The Apache Software Foundation.
+Copyright 2002-2020 The Apache Software Foundation.
 
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).

Modified: turbine/fulcrum/trunk/yaafi-crypto/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/pom.xml?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/pom.xml (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/pom.xml Wed Jul  1 10:26:32 2020
@@ -74,7 +74,7 @@
       <!-- to gt junit 5 -->
       <groupId>org.apache.fulcrum</groupId>
       <artifactId>fulcrum-testcontainer</artifactId>
-      <version>1.0.8</version>
+      <version>1.0.9-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
     <dependency>

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/changes/changes.xml?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/changes/changes.xml (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/changes/changes.xml Wed Jul  1 10:26:32 2020
@@ -25,8 +25,8 @@
 
   <body>
     <release version="1.0.8" date="as in SVN">
-      <action dev="jk" type="update">
-        Add Java 8 PBEWithHmacSHA256AndAES_128 based encryption
+      <action dev="gk" type="update">
+        Added two Java 8 implementations based on PBE (PBEWithHmacSHA256AndAES_128) or GCM (AES/GCM/NoPadding) encryption.
       </action>
       <action dev="painter" type="update">
         Clean up PMD and FindBug reports.  Fixed some typos and updated to conform with Turbine coding style guidelines

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoParameters.java Wed Jul  1 10:26:32 2020
@@ -31,7 +31,12 @@ public interface CryptoParameters
     /** Parameter for PBEParameterSpec */
     int COUNT = 20;
 
-    /** The password salt: update to a method to prevent malicious code bug */
+    /** 
+     * The password salt: update to a method to prevent malicious code bug.
+     * 
+     * @return the salt 
+     * 
+     * */
     public static byte[] Salt() 
     {
     	return new byte[] 
@@ -42,7 +47,6 @@ public interface CryptoParameters
     }
     
     
-    /** The crypto algorithm being used */
-    String ALGORITHM = "PBEWithMD5AndDES";
-    
-}
+    /** 
+     * The default crypto algorithm being used */
+    String ALGORITHM = "PBEWithMD5AndDES";}

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/CryptoStreamFactoryImpl.java Wed Jul  1 10:26:32 2020
@@ -125,6 +125,8 @@ public class CryptoStreamFactoryImpl ext
 
     /**
      * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getSmartInputStream(java.io.InputStream,char[])
+     * 
+     * 
      */
     public InputStream getSmartInputStream(InputStream is, char[] password )
         throws GeneralSecurityException, IOException

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamGCMImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamGCMImpl.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamGCMImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamGCMImpl.java Wed Jul  1 10:26:32 2020
@@ -37,6 +37,7 @@ import javax.crypto.spec.SecretKeySpec;
 import org.apache.fulcrum.jce.crypto.StreamUtil;
 import org.apache.fulcrum.jce.crypto.extended.CryptoParametersJ8;
 import org.apache.fulcrum.jce.crypto.extended.CryptoStreamFactoryJ8Template;
+import org.apache.fulcrum.jce.crypto.extended.CryptoParametersJ8.TYPES;
 
 /**
  * Concrete implementation for creating encrypting/decrypting streams. The
@@ -53,14 +54,18 @@ import org.apache.fulcrum.jce.crypto.ext
  *
  *
  * @author <a href="mailto:gk@apache.org">Georg Kallidis</a>
+ * 
+ * The Implementation for {@link TYPES} GCM.
  */
 
 public final class CryptoStreamGCMImpl extends CryptoStreamFactoryJ8Template
 {  
 
     protected static final int IV_SIZE = 12;
+    
     /**
      * Constructor
+     * @throws GeneralSecurityException  - wraps {@link NoSuchAlgorithmException}
      */
     public CryptoStreamGCMImpl() throws GeneralSecurityException
     {
@@ -76,8 +81,9 @@ public final class CryptoStreamGCMImpl e
      *
      * @param salt the salt for the PBE algorithm
      * @param count the iteration for PBEParameterSpec
+
      */
-    public CryptoStreamGCMImpl( byte[] salt, int count) throws GeneralSecurityException
+    public CryptoStreamGCMImpl( byte[] salt, int count) 
     {
         this.salt = salt;
         this.count = count;
@@ -91,7 +97,7 @@ public final class CryptoStreamGCMImpl e
      * @param password the password to use.
      * @param salt if provided this is used, otherweise {@link #getSalt()}.
      * @return the key
-     * @throws GeneralSecurityException creating the key failed
+     * @throws GeneralSecurityException if creating the key failed
      */
     @Override
     protected Key createKey( char[] password, byte[] salt ) 
@@ -108,7 +114,7 @@ public final class CryptoStreamGCMImpl e
      * @param mode the cipher mode
      * @param password the password
      * @return an instance of a cipher
-     * @throws GeneralSecurityException creating a cipher failed
+     * @throws GeneralSecurityException if creating a cipher failed
      * @throws IOException creating a cipher failed
      */
     @Override
@@ -190,6 +196,11 @@ public final class CryptoStreamGCMImpl e
         return ciphertext;
     }
     
+    /**
+     * 
+     * @return the random byte array from {@link SecureRandom} SHA1PRNG (as default)
+     * @throws GeneralSecurityException - if creating the key failed
+     */
     private byte[] generateIV( ) throws GeneralSecurityException {
         SecureRandom random;
         try {
@@ -202,10 +213,6 @@ public final class CryptoStreamGCMImpl e
         }
     }
 
-    @Override
-    protected Cipher createCipher(int encryptMode, char[] password) throws GeneralSecurityException, IOException {
-        throw new RuntimeException("not provided for this implementation");
-    }
 
 
 }

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamPBEImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamPBEImpl.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamPBEImpl.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/algo/CryptoStreamPBEImpl.java Wed Jul  1 10:26:32 2020
@@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.security.GeneralSecurityException;
 import java.security.Key;
@@ -37,6 +38,7 @@ import javax.crypto.spec.PBEParameterSpe
 
 import org.apache.fulcrum.jce.crypto.StreamUtil;
 import org.apache.fulcrum.jce.crypto.extended.CryptoParametersJ8;
+import org.apache.fulcrum.jce.crypto.extended.CryptoParametersJ8.TYPES;
 import org.apache.fulcrum.jce.crypto.extended.CryptoStreamFactoryJ8Template;
 
 /**
@@ -44,7 +46,7 @@ import org.apache.fulcrum.jce.crypto.ext
  * implementation uses the JCA (Java Crypto Extension) supplied
  * by SUN (using SunJCE 1.42).
  *
- * The implementation uses as @see {@link CryptoParametersJ8#ALGORITHM_J8_PBE} for encryption which
+ * The implementation uses as @see {@link CryptoParametersJ8} ALGORITHM_J8_PBE for encryption which
  * should be sufficient for most applications.
  *
  * The implementation also supplies a default password in the case that
@@ -58,14 +60,18 @@ import org.apache.fulcrum.jce.crypto.ext
  * @author <a href="mailto:gk@apache.org">Georg Kallidis</a>
  * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
  * @author <a href="mailto:maakus@earthlink.net">Markus Hahn</a>
+ * 
+ * The Implementation for {@link TYPES} PBE.
  */
 
 public final class CryptoStreamPBEImpl extends CryptoStreamFactoryJ8Template
 {
 
     protected static final int IV_SIZE = 16;
+
     /**
      * Constructor
+     * @throws GeneralSecurityException
      */
     public CryptoStreamPBEImpl() throws GeneralSecurityException
     {
@@ -81,7 +87,7 @@ public final class CryptoStreamPBEImpl e
      * @param salt the salt for the PBE algorithm
      * @param count the iteration for PBEParameterSpec
      */
-    public CryptoStreamPBEImpl( byte[] salt, int count) throws GeneralSecurityException
+    public CryptoStreamPBEImpl( byte[] salt, int count)
     {
         this.salt = salt;
         this.count = count;
@@ -95,7 +101,7 @@ public final class CryptoStreamPBEImpl e
      * @param password the password to use.
      * @param salt if provided this is used, otherweise {@link #getSalt()}.
      * @return the key
-     * @throws GeneralSecurityException creating the key failed
+     * @throws GeneralSecurityException if creating the key failed
      */
     @Override
     protected Key createKey( char[] password, byte[] salt ) 
@@ -108,7 +114,7 @@ public final class CryptoStreamPBEImpl e
 
         byte[] encodedTmp = null;
         try {
-            if( getProviderName() == null )
+            if( this.getProviderName() == null )
             {
                 keyFactory = SecretKeyFactory.getInstance( algorithm );
             }
@@ -212,10 +218,4 @@ public final class CryptoStreamPBEImpl e
         return ciphertext;
     }
 
-
-    @Override
-    protected Cipher createCipher(int encryptMode, char[] password) throws GeneralSecurityException, IOException {
-        throw new RuntimeException("not provided for this implementation");
-    }
-
 }

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java Wed Jul  1 10:26:32 2020
@@ -46,10 +46,10 @@ import org.apache.fulcrum.jce.crypto.ext
  * 
  * Example :
  * 
- * java -classpath target/classes org.apache.fulcrum.jce.crypto.cli.CLI2 string enc changeit mysecretgeheim
+ * <pre>java -classpath target/classes org.apache.fulcrum.jce.crypto.cli.CLI2 string enc changeit mysecretgeheim</pre>
  * ...
  * 
- * java -cp target/classes org.apache.fulcrum.jce.crypto.cli.Main string dec changeit J8_AES256;<hashcode>
+ * <pre>java -cp target/classes org.apache.fulcrum.jce.crypto.cli.Main string dec changeit J8_AES256 </pre>
  *
  * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
  */
@@ -324,6 +324,8 @@ public class CLI2
      * @param password as char array
      * @param value String to be en/decrypted
      * @throws Exception the operation failed
+     * 
+     * @return the result - either the encrypted or decrypted string depending on cipherMode
      */
     public static String processString(String cipherMode, char[] password, String value)
         throws Exception

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoParametersJ8.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoParametersJ8.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoParametersJ8.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoParametersJ8.java Wed Jul  1 10:26:32 2020
@@ -19,70 +19,70 @@ package org.apache.fulcrum.jce.crypto.ex
  * under the License.
  */
 
-
 /**
  * CryptoParameters used for encryption/decryption.
  *
  * @author <a href="mailto:gk@apache.org">Georg Kallidis</a>
  */
 
-public interface CryptoParametersJ8
-{
+public interface CryptoParametersJ8 {
+
+	/**
+	 * default 
+	 */
+	int COUNT_J8 = 10_000; // 200_000;
+
+	/**
+	 * 
+	 * This module is using PBEWith &lt;digest&gt;And&lt;encryption&gt;:
+	 * 
+	 * <ul>
+	 * <li>PBEWithHmacSHA256AndAES_256/CBC/PKCS5Padding in {@link #ALGORITHM_J8_PBE}</li>
+	 * </ul>
+	 * 
+	 * or Cipher Algorithm Names/Cipher Algorithm Modes/Cipher Algorithm Padding
+	 * 
+	 * <ul>
+	 * <li>AES/GCM/NoPadding in {@link #ALGORITHM_J8_GCM}</li>
+	 * </ul>
+	 * 
+	 * 
+	 * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider">The Oracle Security SunJCE Provider</a>
+	 * 
+	 * Algo/mode/padding for cipher transformation:
+	 * 
+	 * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Cipher">The Oracle Security Standard Names Cipher Algorithms</a>
+	 */
+	public enum TYPES_IMPL {
+		
+		ALGORITHM_J8_PBE("PBEWithHmacSHA256AndAES_256"), 
+		
+		ALGORITHM_J8_GCM("AES/GCM/NoPadding");
+
+		private final String algorithm;
+
+		private TYPES_IMPL(String algo) {
+			algorithm = algo;
+		}
+
+		@Override
+		public String toString() {
+			return this.algorithm;
+		}
+
+		public String getAlgorithm() {
+			return algorithm;
+		}
+	}
+
+	public enum TYPES {
+		PBE, GCM
+	}
 
-    int COUNT_J8 = 10_000; //200_000;
-    
-    /**
-     *  @see https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html#SunJCEProvider
-     *  
-     *  Algo/mode/padding for cipher transformation: 
-     *  @see https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html
-     *  
-     *  using PBEWith &lt;digest&gt;And&lt;encryption&gt;: 
-     *  
-     *  <ul>
-     *  <li>PBEWithHmacSHA256AndAES_256/CBC/PKCS5Padding</li>
-     *  </ul>
-     *  
-     *  or
-     *  Cipher Algorithm Names/Cipher Algorithm Modes/Cipher Algorithm Padding
-     *  
-     *  <ul>
-     *  <li>AES/GCM/NoPadding</li>
-     *  </ul> 
-     */
-    
-    public enum TYPES_IMPL 
-    {
-        ALGORITHM_J8_PBE("PBEWithHmacSHA256AndAES_256"), 
-        ALGORITHM_J8_GCM("AES/GCM/NoPadding");
-        
-        private final String algorithm;
-        
-        private TYPES_IMPL(String algo) 
-        {
-            algorithm = algo;
-        }
-        
-        @Override
-        public String toString() 
-        {
-            return this.algorithm;
-        }
-        
-        public String getAlgorithm() 
-        {
-            return algorithm;
-        }
-    }
-    
-    public enum TYPES {
-        PBE, GCM
-    }
-    
-    /**
-     * Prefix to decrypted hex hash to get a clue, what to use and what it is.
-     * 
-     * This should be always 10 bytes
-     */
-    String CLEAR_CODE_J8 = "J8_AES256;";
+	/**
+	 * Prefix to decrypted hex hash to get a clue, what to use and what it is.
+	 * 
+	 * This should be always 10 bytes
+	 */
+	String CLEAR_CODE_J8 = "J8_AES256;";
 }

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8.java Wed Jul  1 10:26:32 2020
@@ -47,16 +47,4 @@ public interface CryptoStreamFactoryJ8 e
     OutputStream getOutputStream(InputStream is, OutputStream os, char[] password)
         throws GeneralSecurityException, IOException;
     
-    /**
-     * Creates input stream based on the decryption mode
-     * using the default password.
-     *
-     * @param is the input stream to be wrapped
-     * @param decryptionMode the decryption mode (true|false|auto)
-     * @return an decrypting input stream
-     * @throws GeneralSecurityException creating the input stream failed
-     * @throws IOException creating the input stream failed
-     */
-    InputStream getInputStream(InputStream is, char[] password)
-            throws GeneralSecurityException, IOException;
 }

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8Template.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8Template.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8Template.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoStreamFactoryJ8Template.java Wed Jul  1 10:26:32 2020
@@ -33,7 +33,6 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.crypto.Cipher;
 
-import org.apache.fulcrum.jce.crypto.CryptoStreamFactoryImpl;
 import org.apache.fulcrum.jce.crypto.PasswordFactory;
 import org.apache.fulcrum.jce.crypto.StreamUtil;
 import org.apache.fulcrum.jce.crypto.algo.CryptoStreamGCMImpl;
@@ -45,8 +44,27 @@ import org.apache.fulcrum.jce.crypto.ext
  * 
  * 
  **/
-public abstract class CryptoStreamFactoryJ8Template extends CryptoStreamFactoryImpl implements CryptoStreamFactoryJ8
+public abstract class CryptoStreamFactoryJ8Template /*  extends CryptoStreamFactoryImpl*/ implements CryptoStreamFactoryJ8
 {
+	
+	/** the salt for the algorithm */
+    protected byte[] salt;
+
+    /** the count paramter for the algorithm */
+    protected int count;
+
+    /** the name of the JCE provider */
+    protected String providerName;
+
+    /** the algorithm to use */
+    protected String algorithm;
+    
+    /**
+     * The JCE provider name known to work. If the value
+     * is set to null an appropriate provider will be
+     * used.
+     */
+    protected static final String PROVIDERNAME = null;
 
     protected static final int SALT_SIZE = 16; //might increase cipher length
     protected static final int KEY_SIZE = 256;
@@ -62,6 +80,8 @@ public abstract class CryptoStreamFactor
 
     /**
      * Factory method to get a default instance
+     * 
+     * @param type the @see {@link TYPES} of the instance.
      * @return an instance of the CryptoStreamFactory
      */
     public static CryptoStreamFactoryJ8 getInstance(TYPES type) 
@@ -90,7 +110,7 @@ public abstract class CryptoStreamFactor
      *
      * @param salt the salt for the PBE algorithm
      * @param count the iteration for PBEParameterSpec
-     * @paramn type {@link TYPES}
+     * @param type {@link TYPES} what type the algorithm will be
      */
     public CryptoStreamFactoryJ8Template( byte[] salt, int count, TYPES type)
     {
@@ -105,7 +125,7 @@ public abstract class CryptoStreamFactor
     /**
      * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getSmartInputStream(java.io.InputStream)
      */
-    @Override
+
     public InputStream getSmartInputStream(InputStream is)
         throws GeneralSecurityException, IOException
     {
@@ -118,7 +138,6 @@ public abstract class CryptoStreamFactor
     /**
      * @see org.apache.fulcrum.jce.crypto.CryptoStreamFactory#getInputStream(java.io.InputStream,char[])
      */
-    @Override
     public InputStream getInputStream( InputStream is, char[] password )
         throws GeneralSecurityException, IOException
     {
@@ -127,8 +146,6 @@ public abstract class CryptoStreamFactor
         return eis;
     }
 
-    
-    @Override
     public OutputStream getOutputStream(InputStream is, OutputStream os, char[] password)
             throws GeneralSecurityException, IOException {
         byte[] encrypted =  this.createCipher( is, Cipher.ENCRYPT_MODE, password );
@@ -136,6 +153,61 @@ public abstract class CryptoStreamFactor
         StreamUtil.copy(eis, os);
         return os;
     }
+    
+    /**
+     * resets the default instances
+     */
+    public static void resetInstances()
+    {
+        CryptoStreamFactoryJ8Template.instances.clear();
+    }
+    
+    /**
+     * Set the default instances from an external application.
+     * @param instances the new default instances map
+     * @throws Exception if instances are null
+     */
+    public static void setInstances(Map<TYPES,CryptoStreamFactoryJ8Template> instances ) throws Exception
+    {
+    	if (instances == null) throw new Exception("setting instances to null not allowed!");
+        CryptoStreamFactoryJ8Template.instances = instances;
+    }
+    
+    /** not used / implemented methods **/
+    
+    @Override
+	public InputStream getInputStream(InputStream is, String decryptionMode)
+			throws GeneralSecurityException, IOException {
+		throw new UnsupportedOperationException("not implemented");
+	}
+
+	@Override
+	public InputStream getInputStream(InputStream is, String decryptionMode, char[] password)
+			throws GeneralSecurityException, IOException {
+		throw new UnsupportedOperationException("not implemented");
+	}
+
+	@Override
+	public InputStream getInputStream(InputStream is) throws GeneralSecurityException, IOException {
+		throw new UnsupportedOperationException("not implemented");
+	}
+
+	@Override
+	public InputStream getSmartInputStream(InputStream is, char[] password)
+			throws GeneralSecurityException, IOException {
+		throw new UnsupportedOperationException("not implemented");
+	}
+
+	@Override
+	public OutputStream getOutputStream(OutputStream os) throws GeneralSecurityException, IOException {
+		throw new UnsupportedOperationException("not implemented");
+	}
+
+	@Override
+	public OutputStream getOutputStream(OutputStream os, char[] password) throws GeneralSecurityException, IOException {
+		throw new UnsupportedOperationException("not implemented");
+	}
+    /** not used methods end **/
 
     /**
      * Create a PBE key.
@@ -151,19 +223,31 @@ public abstract class CryptoStreamFactor
     /**
      * Create a Cipher.
      *
+     * @param is the input stream
      * @param mode the cipher mode
      * @param password the password
      * @return an instance of a cipher
+     * @return the cipher as byte array
      * @throws GeneralSecurityException creating a cipher failed
      * @throws IOException creating a cipher failed
      */
     protected abstract byte[] createCipher(InputStream is, int mode, char[] password )
         throws GeneralSecurityException, IOException;
     
+    /**
+     * creates salt from {@link SecureRandom#getInstance(String)} by default was algorithm SHA1PRNG
+     * 
+     * changed to {@link SecureRandom#getInstanceStrong()} and let the system decide, what PRNG to use for salt random.
+     * 
+     * salt size by default @link {@value #SALT_SIZE}.
+     * 
+     * @return the generated salt as byte array
+     * @throws GeneralSecurityException if no algo could be found.
+     */
     protected byte[] generateSalt() throws GeneralSecurityException {
         SecureRandom random;
         try {
-            random = SecureRandom.getInstance("SHA1PRNG");
+            random = SecureRandom.getInstanceStrong();
             byte[] salt = new byte[SALT_SIZE ];
             random.nextBytes(salt);
             return salt;
@@ -172,4 +256,36 @@ public abstract class CryptoStreamFactor
         }
     }
 
+	public byte[] getSalt() {
+		return salt;
+	}
+
+	public void setSalt(byte[] salt) {
+		this.salt = salt;
+	}
+
+	public int getCount() {
+		return count;
+	}
+
+	public void setCount(int count) {
+		this.count = count;
+	}
+
+	public String getProviderName() {
+		return providerName;
+	}
+
+	public void setProviderName(String providerName) {
+		this.providerName = providerName;
+	}
+
+	public String getAlgorithm() {
+		return algorithm;
+	}
+
+	public void setAlgorithm(String algorithm) {
+		this.algorithm = algorithm;
+	}
+
 }

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/java/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8.java Wed Jul  1 10:26:32 2020
@@ -32,125 +32,113 @@ import org.apache.fulcrum.jce.crypto.Str
 import org.apache.fulcrum.jce.crypto.extended.CryptoParametersJ8.TYPES;
 
 /**
- * Helper class to provde generic functions to work with CryptoStreams.
+ * Helper class to provide generic functions to work with CryptoStreams.
  *
  * The code uses parts from Markus Hahn's Blowfish library found at
  * http://blowfishj.sourceforge.net/
  *
  * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
  * @author <a href="mailto:maakus@earthlink.net">Markus Hahn</a>
+ * @author <a href="mailto:gk@apache.org">Georg Kallidis</a>
  */
-public final class CryptoUtilJ8 extends CryptoUtil 
-{
+public final class CryptoUtilJ8 extends CryptoUtil {
+
+	/** the typed default instances */
+	private static Map<TYPES, CryptoUtilJ8> cryptoUtilJ8s = new ConcurrentHashMap<>();
 
-    /** the typed default instances */    
-    private static Map<TYPES,CryptoUtilJ8> cryptoUtilJ8s = new ConcurrentHashMap<>();
-    
 	// default see instance
-    public TYPES type;
-    
-    public TYPES getType() 
-    {
-        return type;
-    }
-
-    
-    
-    /**
-     * Factory method to get a default instance
-     * @param type 
-     * @return an instance of the CryptoStreamFactory
-     */
-    public static CryptoUtilJ8 getInstance(TYPES type)
-    {
-        synchronized (CryptoUtilJ8.class) 
-        {
-            if( !cryptoUtilJ8s.containsKey(type) )
-            {
-                cryptoUtilJ8s.put(type, new CryptoUtilJ8(type) );
-            }
-            return cryptoUtilJ8s.get(type);
-        }
-    }
-    
-    /**
-     * Factory method to get a default instance
-     * 
-     * default type PDC
-     * @return an instance of the CryptoStreamFactory
-     */
-    public static CryptoUtilJ8 getInstance()
-    {
-        synchronized (CryptoUtilJ8.class) 
-        {
-            TYPES defaultType = TYPES.PBE;
-            if( cryptoUtilJ8s.isEmpty() && !cryptoUtilJ8s.containsKey(defaultType) )
-            {
-                cryptoUtilJ8s.put(defaultType, new CryptoUtilJ8(defaultType) );
-            }
-            return cryptoUtilJ8s.get(defaultType);
-        }
-    }
-    
-    private CryptoUtilJ8(TYPES type) 
-    {
-        super();
-        this.type = type;
-    }
-    
-    private CryptoUtilJ8() 
-    {
-        super();
-    }
-
-    /**
-     * Copies from a source to a target object using encryption and a caller
-     * supplied CryptoStreamFactory.
-     *
-     * @param factory  the factory to create the crypto streams
-     * @param source   the source object
-     * @param target   the target object
-     * @param password the password to use for encryption
-     * @throws GeneralSecurityException accessing JCE failed
-     * @throws IOException              accessing the source failed
-     */
-    @Override
-    public void encrypt(CryptoStreamFactory factory, Object source, Object target, char[] password)
-            throws GeneralSecurityException, IOException 
-    {
-        InputStream is  = StreamUtil.createInputStream(source);
-        OutputStream os = StreamUtil.createOutputStream(target);
-        OutputStream eos = ( (CryptoStreamFactoryJ8) factory).getOutputStream(is, os, password);
-        // StreamUtil.copy( is, eos );
-    }
-    
-    /**
-     * Copies from a source to a target object using decryption and a caller-suppier
-     * CryptoStreamFactory.
-     *
-     * @param factory  the factory to create the crypto streams
-     * @param source   the source object
-     * @param target   the target object
-     * @param password the password to use for decryption
-     * @throws GeneralSecurityException accessing JCE failed
-     * @throws IOException              accessing the source failed
-     */
-    @Override
-    protected void decrypt(CryptoStreamFactory factory, Object source, Object target, char[] password)
-            throws GeneralSecurityException, IOException 
-    {
-        InputStream is = StreamUtil.createInputStream(source);
-        OutputStream os = StreamUtil.createOutputStream(target);
-        InputStream dis = factory.getInputStream(is, password);
-        StreamUtil.copy(dis, os);
-    }
-
-    /**
-     * 
-     * @return the CryptoStreamFactory to be used
-     */
-    public CryptoStreamFactory getCryptoStreamFactory() 
-    {
-            return CryptoStreamFactoryJ8Template.getInstance(type);
-    }
+	public TYPES type;
+
+	public TYPES getType() {
+		return type;
+	}
+
+	/**
+	 * Factory method to get a default instance
+	 * 
+	 * @param type one of the enum {@link TYPES}.
+	 * @return an instance of the CryptoStreamFactory
+	 */
+	public static CryptoUtilJ8 getInstance(TYPES type) {
+		synchronized (CryptoUtilJ8.class) {
+			if (!cryptoUtilJ8s.containsKey(type)) {
+				cryptoUtilJ8s.put(type, new CryptoUtilJ8(type));
+			}
+			return cryptoUtilJ8s.get(type);
+		}
+	}
+
+	/**
+	 * Factory method to get a default instance
+	 * 
+	 * default type PDC
+	 * 
+	 * @return an instance of the CryptoStreamFactory
+	 */
+	public static CryptoUtilJ8 getInstance() {
+		synchronized (CryptoUtilJ8.class) {
+			TYPES defaultType = TYPES.PBE;
+			if (cryptoUtilJ8s.isEmpty() && !cryptoUtilJ8s.containsKey(defaultType)) {
+				cryptoUtilJ8s.put(defaultType, new CryptoUtilJ8(defaultType));
+			}
+			return cryptoUtilJ8s.get(defaultType);
+		}
+	}
+
+	private CryptoUtilJ8(TYPES type) {
+		super();
+		this.type = type;
+	}
+
+	private CryptoUtilJ8() {
+		super();
+	}
+
+	/**
+	 * Copies from a source to a target object using encryption and a caller
+	 * supplied CryptoStreamFactory.
+	 *
+	 * @param factory  the factory to create the crypto streams
+	 * @param source   the source object
+	 * @param target   the target object
+	 * @param password the password to use for encryption
+	 * @throws GeneralSecurityException accessing JCE failed
+	 * @throws IOException              accessing the source failed
+	 */
+	@Override
+	public void encrypt(CryptoStreamFactory factory, Object source, Object target, char[] password)
+			throws GeneralSecurityException, IOException {
+		InputStream is = StreamUtil.createInputStream(source);
+		OutputStream os = StreamUtil.createOutputStream(target);
+		OutputStream eos = ((CryptoStreamFactoryJ8) factory).getOutputStream(is, os, password);
+		// StreamUtil.copy( is, eos );
+	}
+
+	/**
+	 * Copies from a source to a target object using decryption and a caller-suppier
+	 * CryptoStreamFactory.
+	 *
+	 * @param factory  the factory to create the crypto streams
+	 * @param source   the source object
+	 * @param target   the target object
+	 * @param password the password to use for decryption
+	 * @throws GeneralSecurityException accessing JCE failed
+	 * @throws IOException              accessing the source failed
+	 */
+	@Override
+	protected void decrypt(CryptoStreamFactory factory, Object source, Object target, char[] password)
+			throws GeneralSecurityException, IOException {
+		InputStream is = StreamUtil.createInputStream(source);
+		OutputStream os = StreamUtil.createOutputStream(target);
+		InputStream dis = factory.getInputStream(is, password);
+		StreamUtil.copy(dis, os);
+	}
+
+	/**
+	 * 
+	 * @return the CryptoStreamFactory to be used
+	 */
+	public CryptoStreamFactory getCryptoStreamFactory() {
+		return CryptoStreamFactoryJ8Template.getInstance(type);
+	}
 }

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/test/log4j2.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/test/log4j2.xml?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/test/log4j2.xml (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/test/log4j2.xml Wed Jul  1 10:26:32 2020
@@ -30,10 +30,14 @@
 	    </File>
     </Appenders>
     <Loggers>
-        <Logger name="org.apache.fulcrum.jce.crypto" level="debug" additivity="false">
+      <Logger name="org.apache.fulcrum.jce.crypto" level="debug" additivity="false">
             <AppenderRef ref="console"/>
             <AppenderRef ref="logfile"/>
-        </Logger>
+       </Logger>
+       <Logger name="org.apache.fulcrum.jce" level="debug" additivity="false">
+            <AppenderRef ref="console"/>
+            <AppenderRef ref="logfile"/>
+       </Logger>
       <Logger name="org.apache.fulcrum" level="info" additivity="false">
           <AppenderRef ref="console"/>
           <AppenderRef ref="logfile"/>

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8ParameterizedTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8ParameterizedTest.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8ParameterizedTest.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8ParameterizedTest.java Wed Jul  1 10:26:32 2020
@@ -1,6 +1,5 @@
 package org.apache.fulcrum.jce.crypto.extended;
 
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -24,309 +23,338 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.EnumSource;
 
-
 /**
  * Test suite for crypto functionality
  *
  * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
  */
 public class CryptoUtilJ8ParameterizedTest {
-    /** the password to be used */
-    private String password;
+	/** the password to be used */
+	private String password;
+
+	/** the test data directory */
+	private File testDataDirectory;
+
+	/** the temp data director */
+	private File tempDataDirectory;
+
+	private List<CryptoUtilJ8> cryptoUtilJ8s = new ArrayList<>();
+
+	private static Logger log = LogManager.getLogger(CryptoUtilJ8ParameterizedTest.class);
 
-    /** the test data directory */
-    private File testDataDirectory;
+	/**
+	 * Constructor
+	 */
+	public CryptoUtilJ8ParameterizedTest() {
 
-    /** the temp data director */
-    private File tempDataDirectory;
-    
-    private List<CryptoUtilJ8> cryptoUtilJ8s = new ArrayList<>();
-    
-    private static Logger log = LogManager.getLogger(CryptoUtilJ8ParameterizedTest.class);
-
-    /**
-     * Constructor
-     */
-    public CryptoUtilJ8ParameterizedTest() {
-
-        this.password = "mysecret";
-        this.testDataDirectory = new File("./src/test/data");
-        this.tempDataDirectory = new File("./target/temp");
-        this.tempDataDirectory.mkdirs();
-    }
+		this.password = "mysecret";
+		this.testDataDirectory = new File("./src/test/data");
+		this.tempDataDirectory = new File("./target/temp");
+		this.tempDataDirectory.mkdirs();
+	}
 
-    
 //    @ParameterizedTest
 //    @EnumSource( TYPES.class )
 //    public void setUp(TYPES type) throws Exception {
 //        cryptoUtilJ8 = CryptoUtilJ8.getInstance(type); // (TYPES.PBE);
 //    }
 
-    /**
-     * @return Returns the password.
-     */
-    protected char[] getPassword() {
-        return password.toCharArray();
-    }
-
-    /**
-     * @return Returns the tempDataDirectory.
-     */
-    protected File getTempDataDirectory() {
-        return tempDataDirectory;
-    }
-
-    /**
-     * @return Returns the testDataDirectory.
-     */
-    protected File getTestDataDirectory() {
-        return testDataDirectory;
-    }
-    
-    @AfterEach
-    public void setup() {
-        cryptoUtilJ8s.clear(); 
-    }
-    
-    /** Encrypt a text file 
-     * @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testTextEncryption(TYPES type)  {
-        
-        cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
-        File sourceFile = new File(this.getTestDataDirectory(), "plain.txt");
-        File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.txt");
-        
-        cryptoUtilJ8s.forEach(cuj8 -> {
-            try {
-                log.info("checking "+ cuj8.getType());
-                cuj8.encrypt(sourceFile, targetFile, this.getPassword());
-            } catch (GeneralSecurityException e) {
-                e.printStackTrace();
-                fail();
-            } catch (IOException e) {
-                e.printStackTrace();
-                fail();
-            }
-        } );
-    }
-
-    /** Decrypt a text file 
-     * @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testTextDecryption(TYPES type) {
-        cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
-            cryptoUtilJ8s.forEach(cuj8 -> {
-                log.info("checking "+ cuj8.getType());
-                try {
-                    File sourceFile = new File(this.getTestDataDirectory(), "plain.txt");
-                    File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.txt");
-                    cuj8.encrypt(sourceFile, targetFile, this.getPassword());
-                    
-                    File sourceFile2 = targetFile;
-                    File targetFile2 = new File(this.getTempDataDirectory(), "plain.j8.dec.txt");
-                    cuj8.decrypt(sourceFile2, targetFile2.getAbsolutePath(), this.getPassword());
-                    assertEquals(
-                            new String(Files.readAllBytes( Paths.get(sourceFile.toURI())) ), 
-                            new String(Files.readAllBytes( Paths.get(targetFile2.toURI())) )
-                            );
-                } catch (GeneralSecurityException | IOException e) {
-                    e.printStackTrace();
-                    fail();
-                }
-            });
-    }
-    
-    /** Encrypt a PDF file 
-     * 
-     * @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testPdfEncryption(TYPES type) {
-        cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
-        File sourceFile = new File(this.getTestDataDirectory(), "plain.pdf");
-        File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.pdf");
-        cryptoUtilJ8s.forEach(cuj8 -> { 
-            try {
-                cuj8.encrypt(sourceFile, targetFile, this.getPassword());
-            } catch (GeneralSecurityException | IOException e) {
-                e.printStackTrace();
-                fail();
-            }    
-        });        
-    }
-
-    /** Decrypt a PDF file 
-     * 
-     * @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testPdfDecryption(TYPES type)  {
-        cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
-        //testPdfEncryption();
-        cryptoUtilJ8s.forEach(cuj8 -> { 
-            try {
-                File sourceFile = new File(this.getTestDataDirectory(), "plain.pdf");
-                File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.pdf");
-                cuj8.encrypt(sourceFile, targetFile, this.getPassword());
-                
-                File sourceFile2 = targetFile;
-                File targetFile2 = new File(this.getTempDataDirectory(), "plain.j8.dec.pdf");
-                cuj8.decrypt(sourceFile2, targetFile2, this.getPassword());
-                
-                assertEquals(
-                        new String(Files.readAllBytes( Paths.get(sourceFile.toURI())) ), 
-                        new String(Files.readAllBytes( Paths.get(targetFile2.toURI())) )
-                        );
-            } catch (GeneralSecurityException | IOException e) {
-                e.printStackTrace();
-                fail();
-            }    
-        }); 
-
-    }
-
-    /** Test encryption and decryption of Strings
-     * 
-     *  @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testStringEncryption(TYPES type) {
-        CryptoUtilJ8 cuj8= CryptoUtilJ8.getInstance(type);
-        char[] testVector = new char[513];
-
-        for (int i = 0; i < testVector.length; i++) {
-            testVector[i] = (char) i;
-        }
-
-        String source = new String(testVector);
-        String cipherText = null;
-        String plainText = null;
-        try {
-            log.debug("without clearTextHeader");
-            cipherText = cuj8.encryptString(source, this.getPassword());
-            plainText = cuj8.decryptString(cipherText, this.getPassword());
-            assertEquals(source, plainText, source +" is not equal with " + plainText);
-            
-            log.debug("with clearTextHeader in encrypted string:" + CryptoParametersJ8.CLEAR_CODE_J8);
-            String cipherText2 = cuj8.encryptStringWithClearCode(source, this.getPassword());
-            
-            assertTrue(cipherText2.startsWith(CryptoParametersJ8.CLEAR_CODE_J8), cipherText2 +" does not start with " + CryptoParametersJ8.CLEAR_CODE_J8);
-            String plainText2 = cuj8.decryptStringWithClearCode(cipherText2, this.getPassword());
-            assertEquals(source, plainText2, source +" is not equal with " + plainText);
-            
-        } catch (GeneralSecurityException | IOException e) {
-            e.printStackTrace();
-            fail();
-        }
-    }
-
-    /** Test encryption and decryption of Strings
-     * @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testStringHandling(TYPES type)  {
-        cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
-        String source = "Nobody knows the toubles I have seen ...";
-        cryptoUtilJ8s.forEach(cuj8 -> { 
-            String cipherText;
-            try {
-                cipherText = cuj8.encryptString(source, this.getPassword());
-                String plainText = cuj8.decryptString(cipherText, this.getPassword());
-                assertEquals(source, plainText);   
-            } catch (GeneralSecurityException | IOException e) {
-                e.printStackTrace();
-                fail();
-            }
-         
-        });
-
-    }
-
-    /** Test creating a password
-     * @throws Exception Generic exception
-     */
-    @Test
-    public void testPasswordFactory() throws Exception {
-        char[] result = null;
-        result = PasswordFactory.getInstance("SHA-256").create();
-        log.info("random pw:" + new String(result));
-        result = PasswordFactory.getInstance("SHA-256",10_000).create(this.getPassword());
-        log.info("password pw with seed:" + new String(result));
-        assertNotNull(result);
-        return;
-    }
-    
-    /** Test encryption and decryption of binary data
-     * @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testBinaryHandling(TYPES type) throws Exception {
-        cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
-        cryptoUtilJ8s.forEach(cuj8 -> { 
-            byte[] source = new byte[256];
-            byte[] result = null;
-
-            for (int i = 0; i < source.length; i++) {
-                source[i] = (byte) i;
-            }
-
-            ByteArrayOutputStream cipherText = new ByteArrayOutputStream();
-            ByteArrayOutputStream plainText = new ByteArrayOutputStream();
-            try {
-                cuj8.encrypt(source, cipherText, this.getPassword());
-                cuj8.decrypt(cipherText, plainText, this.getPassword());
-            } catch (GeneralSecurityException | IOException e) {
-                e.printStackTrace();
-                fail();
-            }
-            result = plainText.toByteArray();
-
-            for (int i = 0; i < source.length; i++) {
-                if (source[i] != result[i]) {
-                    fail("Binary data are different at position " + i);
-                }
-            }
-        });
-
-       
-
-    }
-    
-    /** Test encryption and decryption of Strings 
-     * @throws Exception Generic exception
-     */
-    @ParameterizedTest
-    @EnumSource( TYPES.class )
-    public void testStringWithPasswordEncryption(TYPES type) {
-        char[] password = "57cb-4a23-d838-45222".toCharArray();
-        String source = "e02c-3b76-ff1e-5d9a1";
-        CryptoUtilJ8 cuj8 = CryptoUtilJ8.getInstance(type);
-        log.debug("checking "+ cuj8.getType());
-        String cipherText = null;
-        try {
-            cipherText = cuj8.encryptString(source, password);
-            log.info(cipherText);// about 128 
-            log.info("length for " + cuj8.getType() + " is:" +cipherText.length());// about 128
-            if (cuj8.type == TYPES.PBE) {
-                assertEquals(128, cipherText.length()); // 128bytes + 10 bytes for cleartext
-            } 
-            CryptoStreamFactoryJ8Template.setInstance(null);
-            String plainText = cuj8.decryptString(cipherText, password);
-            assertEquals(source, plainText);
-        } catch (GeneralSecurityException | IOException e) {
-            e.printStackTrace();
-            fail();
-        }      
-    }
+	/**
+	 * @return Returns the password.
+	 */
+	protected char[] getPassword() {
+		return password.toCharArray();
+	}
+
+	/**
+	 * @return Returns the tempDataDirectory.
+	 */
+	protected File getTempDataDirectory() {
+		return tempDataDirectory;
+	}
+
+	/**
+	 * @return Returns the testDataDirectory.
+	 */
+	protected File getTestDataDirectory() {
+		return testDataDirectory;
+	}
+
+	@AfterEach
+	public void setup() {
+		cryptoUtilJ8s.clear();
+	}
+
+	/**
+	 * Parameterized Test
+	 * 
+	 * Encrypt a text file
+	 * 
+	 * @param type the type to be tested based on {@link TYPES}
+	 * 
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testTextEncryption(TYPES type) {
+
+		cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
+		File sourceFile = new File(this.getTestDataDirectory(), "plain.txt");
+		File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.txt");
+
+		cryptoUtilJ8s.forEach(cuj8 -> {
+			try {
+				log.info("checking " + cuj8.getType());
+				cuj8.encrypt(sourceFile, targetFile, this.getPassword());
+			} catch (GeneralSecurityException e) {
+				e.printStackTrace();
+				fail();
+			} catch (IOException e) {
+				e.printStackTrace();
+				fail();
+			}
+		});
+	}
+
+	/**
+	 * Parameterized Test Decrypt a text file
+	 * 
+	 * @param type the type to be tested based on {@link TYPES}
+	 * 
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testTextDecryption(TYPES type) {
+		cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
+		cryptoUtilJ8s.forEach(cuj8 -> {
+			log.info("checking " + cuj8.getType());
+			try {
+				File sourceFile = new File(this.getTestDataDirectory(), "plain.txt");
+				File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.txt");
+				cuj8.encrypt(sourceFile, targetFile, this.getPassword());
+
+				File sourceFile2 = targetFile;
+				File targetFile2 = new File(this.getTempDataDirectory(), "plain.j8.dec.txt");
+				cuj8.decrypt(sourceFile2, targetFile2.getAbsolutePath(), this.getPassword());
+				assertEquals(new String(Files.readAllBytes(Paths.get(sourceFile.toURI()))),
+						new String(Files.readAllBytes(Paths.get(targetFile2.toURI()))));
+			} catch (GeneralSecurityException | IOException e) {
+				e.printStackTrace();
+				fail();
+			}
+		});
+	}
+
+	/**
+	 * Parameterized Test
+	 * 
+	 * Encrypt a PDF file
+	 * 
+	 * @param type the type to be tested based on {@link TYPES}
+	 * 
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testPdfEncryption(TYPES type) {
+		cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
+		File sourceFile = new File(this.getTestDataDirectory(), "plain.pdf");
+		File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.pdf");
+		cryptoUtilJ8s.forEach(cuj8 -> {
+			try {
+				cuj8.encrypt(sourceFile, targetFile, this.getPassword());
+			} catch (GeneralSecurityException | IOException e) {
+				e.printStackTrace();
+				fail();
+			}
+		});
+	}
+
+	/**
+	 * Parameterized Test Decrypt a PDF file
+	 *
+	 * @param type the type to be tested based on {@link TYPES}
+	 * 
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testPdfDecryption(TYPES type) {
+		cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
+		// testPdfEncryption();
+		cryptoUtilJ8s.forEach(cuj8 -> {
+			try {
+				File sourceFile = new File(this.getTestDataDirectory(), "plain.pdf");
+				File targetFile = new File(this.getTempDataDirectory(), "plain.j8.enc.pdf");
+				cuj8.encrypt(sourceFile, targetFile, this.getPassword());
+
+				File sourceFile2 = targetFile;
+				File targetFile2 = new File(this.getTempDataDirectory(), "plain.j8.dec.pdf");
+				cuj8.decrypt(sourceFile2, targetFile2, this.getPassword());
+
+				assertEquals(new String(Files.readAllBytes(Paths.get(sourceFile.toURI()))),
+						new String(Files.readAllBytes(Paths.get(targetFile2.toURI()))));
+			} catch (GeneralSecurityException | IOException e) {
+				e.printStackTrace();
+				fail();
+			}
+		});
+
+	}
+
+	/**
+	 * Parameterized Test Test encryption and decryption of Strings
+	 * 
+	 * @param type the type to be tested based on {@link TYPES}
+	 * 
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testStringEncryption(TYPES type) {
+		CryptoUtilJ8 cuj8 = CryptoUtilJ8.getInstance(type);
+		char[] testVector = new char[513];
+
+		for (int i = 0; i < testVector.length; i++) {
+			testVector[i] = (char) i;
+		}
+
+		String source = new String(testVector);
+		String cipherText = null;
+		String plainText = null;
+		try {
+			log.info("Test without clearTextHeader");
+			cipherText = cuj8.encryptString(source, this.getPassword());
+			// log.debug(cipherText);
+			plainText = cuj8.decryptString(cipherText, this.getPassword());
+			assertEquals(source, plainText, source + " is not equal with " + plainText);
+
+			log.info(String.format("Test with clearTextHeader %s in encrypted string.",
+					CryptoParametersJ8.CLEAR_CODE_J8));
+			String cipherText2 = cuj8.encryptStringWithClearCode(source, this.getPassword());
+			// log.debug(cipherText2);
+			assertTrue(cipherText2.startsWith(CryptoParametersJ8.CLEAR_CODE_J8),
+					String.format("%s does not start with '%s'", cipherText2, CryptoParametersJ8.CLEAR_CODE_J8));
+			String plainText2 = cuj8.decryptStringWithClearCode(cipherText2, this.getPassword());
+			assertEquals(source, plainText2, String.format("%s is not equal with %s", source, plainText));
+
+		} catch (GeneralSecurityException | IOException e) {
+			e.printStackTrace();
+			fail();
+		}
+	}
+
+	/**
+	 * Parameterized Test Test encryption and decryption of Strings
+	 * 
+	 * @param type the type to be tested based on {@link TYPES}
+	 * 
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testStringHandling(TYPES type) {
+		cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
+		String source = "Nobody knows the toubles I have seen ...";
+		cryptoUtilJ8s.forEach(cuj8 -> {
+			String cipherText;
+			try {
+				cipherText = cuj8.encryptString(source, this.getPassword());
+				String plainText = cuj8.decryptString(cipherText, this.getPassword());
+				assertEquals(source, plainText);
+			} catch (GeneralSecurityException | IOException e) {
+				e.printStackTrace();
+				fail();
+			}
+
+		});
+
+	}
+
+	/**
+	 * Test creating a password
+	 * 
+	 * @throws Exception Generic exception
+	 */
+	@Test
+	public void testPasswordFactory() throws Exception {
+		char[] result = null;
+		result = PasswordFactory.getInstance("SHA-256").create();
+		log.info("random pw:" + new String(result));
+		result = PasswordFactory.getInstance("SHA-256", 10_000).create(this.getPassword());
+		log.info("password pw with seed:" + new String(result));
+		assertNotNull(result);
+		return;
+	}
+
+	/**
+	 * Parameterized Test
+	 * 
+	 * Test encryption and decryption of binary data
+	 * 
+	 * @throws Exception Generic exception
+	 * 
+	 * @param type the type to be tested based on {@link TYPES}
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testBinaryHandling(TYPES type) throws Exception {
+		cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
+		cryptoUtilJ8s.forEach(cuj8 -> {
+			byte[] source = new byte[256];
+			byte[] result = null;
+
+			for (int i = 0; i < source.length; i++) {
+				source[i] = (byte) i;
+			}
+
+			ByteArrayOutputStream cipherText = new ByteArrayOutputStream();
+			ByteArrayOutputStream plainText = new ByteArrayOutputStream();
+			try {
+				cuj8.encrypt(source, cipherText, this.getPassword());
+				cuj8.decrypt(cipherText, plainText, this.getPassword());
+			} catch (GeneralSecurityException | IOException e) {
+				e.printStackTrace();
+				fail();
+			}
+			result = plainText.toByteArray();
+
+			for (int i = 0; i < source.length; i++) {
+				if (source[i] != result[i]) {
+					fail("Binary data are different at position " + i);
+				}
+			}
+		});
+
+	}
+
+	/**
+	 * Parameterized Test
+	 * 
+	 * Test encryption and decryption of Strings
+	 * 
+	 * @param type the type to be tested based on {@link TYPES}
+	 * 
+	 */
+	@ParameterizedTest
+	@EnumSource(TYPES.class)
+	public void testStringWithPasswordEncryption(TYPES type) {
+		char[] password = "57cb-4a23-d838-45222".toCharArray();
+		String source = "e02c-3b76-ff1e-5d9a1";
+		CryptoUtilJ8 cuj8 = CryptoUtilJ8.getInstance(type);
+		log.debug("checking type " + cuj8.getType());
+		String cipherText = null;
+		try {
+			cipherText = cuj8.encryptString(source, password);
+			log.info(cipherText);// about 128
+			log.info(String.format("length for %s is %d", cuj8.getType(), cipherText.length()));// about 128
+			if (cuj8.type == TYPES.PBE) {
+				assertEquals(128, cipherText.length()); // 128bytes + 10 bytes for cleartext
+			}
+			if (cuj8.type == TYPES.GCM) {
+				assertEquals(128, cipherText.length());
+			}
+			String plainText = cuj8.decryptString(cipherText, password);
+			assertEquals(source, plainText);
+		} catch (GeneralSecurityException | IOException e) {
+			e.printStackTrace();
+			fail();
+		}
+	}
 
 }

Modified: turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8Test.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8Test.java?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8Test.java (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/src/test/org/apache/fulcrum/jce/crypto/extended/CryptoUtilJ8Test.java Wed Jul  1 10:26:32 2020
@@ -64,8 +64,10 @@ public class CryptoUtilJ8Test {
             cryptoUtilJ8s.add(CryptoUtilJ8.getInstance(type));
         }
         for (CryptoUtilJ8 cryptoUtilJ8 : cryptoUtilJ8s) {
-            log.debug("registered cryptoUtilsJ8: {}", cryptoUtilJ8.getType() );
-            log.debug( ((CryptoStreamFactoryJ8Template)cryptoUtilJ8.getCryptoStreamFactory()).getAlgorithm());
+            log.debug("registered {}: {}", cryptoUtilJ8.getClass().getSimpleName(), cryptoUtilJ8.getType() );
+            CryptoStreamFactoryJ8Template crt = ((CryptoStreamFactoryJ8Template)cryptoUtilJ8.getCryptoStreamFactory());
+            log.debug(String.format("created default crypto factory instance %s for algo %s", crt.getClass().getSimpleName(),
+            		crt.getAlgorithm()));
         }
 
     }
@@ -97,7 +99,7 @@ public class CryptoUtilJ8Test {
     }
     
     /** Encrypt a text file 
-     * @throws Exception Generic exception
+     * 
      */
     @Test
     public void testTextEncryption()  {
@@ -119,7 +121,6 @@ public class CryptoUtilJ8Test {
     }
 
     /** Decrypt a text file 
-     * @throws Exception Generic exception
      */
     @Test
     public void testTextDecryption() {           
@@ -145,7 +146,6 @@ public class CryptoUtilJ8Test {
     
     /** Encrypt a PDF file 
      * 
-     * @throws Exception Generic exception
      */
     @Test
     public void testPdfEncryption() {
@@ -163,7 +163,6 @@ public class CryptoUtilJ8Test {
 
     /** Decrypt a PDF file 
      * 
-     * @throws Exception Generic exception
      */
     @Test
     public void testPdfDecryption()  {
@@ -192,7 +191,6 @@ public class CryptoUtilJ8Test {
 
     /** Test encryption and decryption of Strings
      * 
-     *  @throws Exception Generic exception
      */
     @Test
     public void testStringEncryption() {
@@ -221,7 +219,6 @@ public class CryptoUtilJ8Test {
     }
 
     /** Test encryption and decryption of Strings
-     * @throws Exception Generic exception
      */
     @Test
     public void testStringHandling()  {
@@ -241,7 +238,8 @@ public class CryptoUtilJ8Test {
 
     }
 
-    /** Test creating a password
+    /** 
+     * Test creating a password
      * @throws Exception Generic exception
      */
     @Test
@@ -291,8 +289,8 @@ public class CryptoUtilJ8Test {
 
     }
     
-    /** Test encryption and decryption of Strings 
-     * @throws Exception Generic exception
+    /** 
+     * Test encryption and decryption of Strings 
      */
     @Test
     public void testStringWithPasswordEncryption() {
@@ -309,7 +307,7 @@ public class CryptoUtilJ8Test {
                 if (cuj8.type == TYPES.PBE) {
                     assertEquals(128, cipherText.length()); // 128bytes + 10 bytes for cleartext
                 } 
-                CryptoStreamFactoryJ8Template.setInstance(null);
+                CryptoStreamFactoryJ8Template.resetInstances();
                 String plainText = cuj8.decryptString(cipherText, password);
                 assertEquals(source, plainText);
             } catch (GeneralSecurityException | IOException e) {

Modified: turbine/fulcrum/trunk/yaafi-crypto/xdocs/downloads.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi-crypto/xdocs/downloads.xml?rev=1879399&r1=1879398&r2=1879399&view=diff
==============================================================================
--- turbine/fulcrum/trunk/yaafi-crypto/xdocs/downloads.xml (original)
+++ turbine/fulcrum/trunk/yaafi-crypto/xdocs/downloads.xml Wed Jul  1 10:26:32 2020
@@ -31,12 +31,14 @@
         </tr>
         <tr>
           <td>
-            <a href="http://www.apache.org/dyn/closer.cgi/turbine/fulcrum/fulcrum-yaafi-crypto/binaries/fulcrum-yaafi-crypto-1.0.6-bin.zip">Fulcrum's YAAFI Crypto v1.0.6</a>
-          </td>
-          <td>
+            <p><a href="http://www.apache.org/dyn/closer.cgi/turbine/fulcrum/fulcrum-yaafi-crypto/binaries/fulcrum-yaafi-crypto-1.0.6-bin.zip">Fulcrum's YAAFI Crypto v1.0.6</a>
+            </p><p>
             <a href="http://www.apache.org/dyn/closer.cgi/turbine/fulcrum/fulcrum-yaafi-crypto/binaries/fulcrum-yaafi-crypto-1.0.7-bin.zip">Fulcrum's YAAFI Crypto v1.0.7</a>
+            </p>
+            <p>
+            <a href="http://www.apache.org/dyn/closer.cgi/turbine/fulcrum/fulcrum-yaafi-crypto/binaries/fulcrum-yaafi-crypto-1.0.8-bin.zip">Fulcrum's YAAFI Crypto v1.0.8</a>
+            </p>
           </td>
-
           <td>
             <a href="announcements/announcement-1.0.6.txt">1.0.6</a>
           </td>