in src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java [269:303]
private static CryptoUtilJ8 createCryptoUtil(String cipherMode) throws Exception {
CryptoUtilJ8 cryptoUtilJ8 = null;
List<String> supportedTypes = CryptoParametersJ8.init();
// no extension like enc:GCM
if (cipherMode.substring("enc".length()).equals("")) {
if (supportedTypes.stream().anyMatch(x-> x.equals(CryptoParametersJ8.DEFAULT_TYPE.toString()) )) {
System.err.println("using default type:"+ CryptoParametersJ8.DEFAULT_TYPE);
cryptoUtilJ8 = CryptoUtilJ8.getInstance();
} else {
System.err.println("Could not use default type:"+ TYPES.PBE + ".You have to set explicit type, e.g. enc:"+supportedTypes.get(0) );
}
} else {
System.err.println("checking supported types:"+ supportedTypes);
List<String> matchedType = supportedTypes.stream().filter(x-> cipherMode.endsWith(x) ).collect(Collectors.toList());
System.err.println("matched type:"+ matchedType);
Optional<TYPES> algoShortcut = Arrays.stream(CryptoParametersJ8.TYPES.values())
.filter(a -> matchedType.get(0).equals(a.toString())).findFirst();
if (algoShortcut.isPresent()) {
System.err.println("initializing type:"+ algoShortcut);
cryptoUtilJ8 = CryptoUtilJ8.getInstance(algoShortcut.get());
}
}
if (cryptoUtilJ8 == null) {
throw new Exception("Could not use algorithm. Check debug output and JDK provided algo shortcuts with CLI2 info!");
}
if (debug) {
CryptoStreamFactoryJ8Template crt = ((CryptoStreamFactoryJ8Template)cryptoUtilJ8.getCryptoStreamFactory());
System.err.println(String.format("using crypto factory instance %s for algo %s and type %s with salt length: %s and count %s",
crt.getClass().getSimpleName(), crt.getType(),
crt.getAlgorithm(), crt.getSalt().length, crt.getCount()));
}
return cryptoUtilJ8;
}