- add debug info
- more complete examples
git-svn-id: https://svn.apache.org/repos/asf/turbine/fulcrum/trunk/yaafi-crypto@1880256 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java b/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java
index e6ba487..84ad218 100644
--- a/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java
+++ b/src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java
@@ -115,8 +115,9 @@
private static void printInfo() {
CryptoUtilJ8 cryptoUtilJ8 = CryptoUtilJ8.getInstance();
System.out.println("");
- System.out.println("\t|Crypto factory class: \t" + cryptoUtilJ8.getCryptoStreamFactory().getClass());
+ System.out.println("\t| Default Crypto factory class: \t" + cryptoUtilJ8.getCryptoStreamFactory().getClass());
System.out.println("\t|_Default Algorithm used: \t" + cryptoUtilJ8.getCryptoStreamFactory().getAlgorithm());
+
List<String> algoShortList = Arrays.stream(CryptoParametersJ8.TYPES.values()).map(t -> t.toString())
.collect(Collectors.toList());
System.out.println("\t|Algorithms (shortcut) available: \t" + algoShortList);
@@ -139,6 +140,14 @@
result:
CryptoParametersJ8.getSupportedAlgos(algoList, type, false)), type));
System.out.println("");
+ if (debug) {
+ Arrays.stream(CryptoParametersJ8.TYPES.values()).forEach(t -> {
+ CryptoUtilJ8 testcu = CryptoUtilJ8.getInstance(t);
+ System.out.println("\t| Crypto factory class: \t" + testcu.getCryptoStreamFactory().getClass());
+ System.out.println("\t|_Algorithm used: \t" + testcu.getCryptoStreamFactory().getAlgorithm());
+
+ });
+ }
System.out.println(
"\t|_ More Info: https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html\r\n");
}
@@ -151,21 +160,21 @@
System.out.println(
"\r\n\t*** Command line tool for encrypting/decrypting strings/files ***\r\n\t*** algorithm based on "
+ CryptoParametersJ8.TYPES_IMPL.ALGORITHM_J8_PBE + "***\r\n");
- System.out.println("\tjava -cp target\\classes; " + CLI2.class.getName()
+ System.out.println("\tjava -cp target\\classes " + CLI2.class.getName()
+ " <operation mode> <coding mode> <password> <path|string> [target]\r\n");
System.out.println(
"\tjava -jar target/fulcrum-yaafi-crypto-1.0.8-SNAPSHOT.jar <operation mode> <coding mode> <password> <path|string> [target]\r\n");
- System.out.println("\t\t-------------------");
- System.out.println("\t\toperation mode: file|string|info");
- System.out.println("\t\tcoding mode: enc|dec|enc:GCM. Default algorithm is " + TYPES.PBE);
- System.out.println("\t\t<password: string or empty:''");
- System.out.println("\t\tcode|coderef: path|string");
- System.out.println("\t\ttarget: optional\r\n");
- System.out.println("\t\t-------------------");
+ System.out.println("\t-------------------");
+ System.out.println("\toperation mode: file|string|info");
+ System.out.println("\tcoding mode: enc|dec|enc:GCM. Default algorithm is " + TYPES.PBE);
+ System.out.println("\t<password: string or empty:''");
+ System.out.println("\tcode|coderef: path|string");
+ System.out.println("\ttarget: optional\r\n");
+ System.out.println("\t-------------------");
System.out.println("\t*** Usage: ***\r\n");
- System.out.println("\t\t" + CLI2.class.getSimpleName() + " file [enc|dec] passwd source [target]");
- System.out.println("\t\t" + CLI2.class.getSimpleName() + " string [enc|dec] passwd source");
- System.out.println("\t\t" + CLI2.class.getSimpleName() + " info");
+ System.out.println("\t" + CLI2.class.getSimpleName() + " file [enc|dec] passwd source [target]");
+ System.out.println("\t" + CLI2.class.getSimpleName() + " string [enc|dec] passwd source");
+ System.out.println("\t" + CLI2.class.getSimpleName() + " info");
}
/**
@@ -368,4 +377,4 @@
final Matcher matcher = HEXADECIMAL_PATTERN.matcher(input);
return matcher.matches();
}
-}
\ No newline at end of file
+}
diff --git a/xdocs/examples.xml b/xdocs/examples.xml
index 5dd4c01..d0c6102 100644
--- a/xdocs/examples.xml
+++ b/xdocs/examples.xml
@@ -28,17 +28,43 @@
<section name="Short Examples">
<subsection name="Command line Usage">
<p>
+Encrypt with default PCM the string "mysecretgeheim" and meta password "changeit", outputs encrypted string to stdout.
<source>
<![CDATA[
java -classpath target/classes org.apache.fulcrum.jce.crypto.cli.CLI2 string enc changeit mysecretgeheim
]]>
</source>
+ <source>
+ <![CDATA[
+ java -jar target/fulcrum-yaafi-crypto-<version>.jar string enc:GCM changeit mysecretgeheim
+ ]]>
+ </source>
+This prints out the encrypted "mysecretgeheim".
+ <source>
+ <![CDATA[
+ java -jar target/fulcrum-yaafi-crypto-<version>.jar string dec:GCM changeit 88f8ecc93cc921672e13862d75f90c55a4cc2d823c36e6ac3da0225e397770f45d3944f6be859fe25d053a8442313a5a2581e7edf081030e
+ ]]>
+ </source>
+This decrypts the result to stdout and prints information (supported type, matched type ..) to system.err.
</p>
- <p>An example using an ant build tool and property file is the provided Integration Test in pom.xml.
- By default running this will write the encrypted password to src/filters/filter-integration-test.properties and the decrypted password to target/integration-test/filtered-pw.properties. On the command line with custom password and meta password this is done like this (assuming -Dskip.pw.gen=false -Dskip.pw.encrypt=false):
+ <p>CLI Usage Help:
+ <source>
+ <![CDATA[
+ java -jar target/fulcrum-yaafi-crypto-<version>.jar help
+ ]]>
+ </source>
+ Information about supported cipher libs:
+ <source>
+ <![CDATA[
+ java -jar target/fulcrum-yaafi-crypto-<version>.jar info
+ ]]>
+ </source>
+ </p>
+ <p>An example using an ant build tool and property file is provided in pom-xml with phase integration-test.
+ By default running this will write the encrypted password to target/integration-test/filter-integration-test.properties and the decrypted password to target/integration-test/filtered-pw.properties. You could play with this toll on the command line providing a custom secret and meta password like this (assuming -Dskip.pw.gen=false -Dskip.pw.encrypt=false):
<source>
<![CDATA[
-mvn integration-test -Dtest.password="xyz" -Dmeta.pw="abc"
+mvn integration-test -Dtest.password="xyz" -Dmeta.pw="abc"
]]>
</source>
</p>
@@ -325,8 +351,7 @@
<p>This example could be extended or adapted, eg. by using multiple passwords, or encrypting an entire file.
Have fun!
</p>
- <p>TODO Show gradle example..
- </p>
+
</subsection>
</section>