feat: add bc support

This commit is contained in:
2021-07-21 00:04:49 +08:00
parent 961fbddd63
commit 324aee0ff6
5 changed files with 13 additions and 3 deletions

View File

@@ -12,8 +12,9 @@
}, },
"repo": { "repo": {
"dependencies": [ "dependencies": [
"me.hatter:commons:3.34", "me.hatter:commons:3.36",
"info.picocli:picocli:4.6.1" "info.picocli:picocli:4.6.1",
"org.bouncycastle:bcprov-jdk15on:1.69"
], ],
"testDependencies": [ "testDependencies": [
"junit:junit:4.12" "junit:junit:4.12"

View File

@@ -40,6 +40,9 @@ public class TinyEncryptArgs {
@CommandLine.Option(names = {"-P", "--pgp"}, description = "Decrypt use PGP") @CommandLine.Option(names = {"-P", "--pgp"}, description = "Decrypt use PGP")
boolean pgp = false; boolean pgp = false;
@CommandLine.Option(names = {"--use-jce"}, description = "Use JCE")
boolean useJce = false;
@CommandLine.Parameters(paramLabel = "FILE", description = "Encrypt or Decrypt files") @CommandLine.Parameters(paramLabel = "FILE", description = "Encrypt or Decrypt files")
File[] files; File[] files;

View File

@@ -8,6 +8,7 @@ import me.hatter.tools.commons.io.RFile;
import me.hatter.tools.commons.log.LogConfig; import me.hatter.tools.commons.log.LogConfig;
import me.hatter.tools.commons.log.LogTool; import me.hatter.tools.commons.log.LogTool;
import me.hatter.tools.commons.log.LogTools; import me.hatter.tools.commons.log.LogTools;
import me.hatter.tools.commons.security.bc.BCUtil;
import me.hatter.tools.commons.security.digest.Digests; import me.hatter.tools.commons.security.digest.Digests;
import me.hatter.tools.commons.security.key.KeyPairTool; import me.hatter.tools.commons.security.key.KeyPairTool;
import me.hatter.tools.commons.security.key.KeyUtil; import me.hatter.tools.commons.security.key.KeyUtil;
@@ -157,6 +158,7 @@ public class TinyEncryptMain {
if (tinyEncryptArgs == null) { if (tinyEncryptArgs == null) {
return; return;
} }
BCUtil.useBc(!tinyEncryptArgs.useJce);
// ==================================================================================== // ====================================================================================
if (tinyEncryptArgs.doInitConfig) { // --init-config if (tinyEncryptArgs.doInitConfig) { // --init-config
doInitConfig(tinyEncryptArgs); doInitConfig(tinyEncryptArgs);

View File

@@ -1,7 +1,7 @@
package me.hatter.tools.tinyencrypt.config; package me.hatter.tools.tinyencrypt.config;
public class TinyEncryptConstant { public class TinyEncryptConstant {
public static final String VERSION = "0.3.8"; public static final String VERSION = "0.3.9";
public static final String ENC_FILE_EXT = ".tinyenc"; public static final String ENC_FILE_EXT = ".tinyenc";
} }

View File

@@ -69,9 +69,13 @@ public class EncryptedFileUtil {
log.debug("Start process: " + pb.command()); log.debug("Start process: " + pb.command());
Process p = pb.start(); Process p = pb.start();
p.waitFor(); p.waitFor();
log.info("Finished command");
try { try {
byte[] jsonBytes = IOUtil.readToBytes(p.getInputStream()); byte[] jsonBytes = IOUtil.readToBytes(p.getInputStream());
String jsonStr = new String(jsonBytes, StandardCharsets.UTF_8); String jsonStr = new String(jsonBytes, StandardCharsets.UTF_8);
if (log.isDebugEnable()) {
log.debug("Read cmd JSON: " + jsonStr);
}
JSONObject jo = JSON.parseObject(jsonStr); JSONObject jo = JSON.parseObject(jsonStr);
dataKey = Bytes.fromHex(jo.getString("text_hex")).bytes(); dataKey = Bytes.fromHex(jo.getString("text_hex")).bytes();
} catch (Exception e) { } catch (Exception e) {