feat: v0.3.4, add --digest
This commit is contained in:
@@ -13,6 +13,9 @@ public class TinyEncryptArgs {
|
||||
@CommandLine.Option(names = {"-d", "--decrypt"}, description = "Decrypt file")
|
||||
boolean decrypt = false;
|
||||
|
||||
@CommandLine.Option(names = {"--digest"}, description = "Calc source file digest(SHA256)")
|
||||
boolean digest = false;
|
||||
|
||||
@CommandLine.Option(names = {"-s", "--show"}, description = "Show decrypted text in window")
|
||||
boolean showInWindow = false;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.hatter.tools.tinyencrypt;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import me.hatter.tools.commons.bytes.Bytes;
|
||||
import me.hatter.tools.commons.exception.JumpOutException;
|
||||
import me.hatter.tools.commons.io.RFile;
|
||||
import me.hatter.tools.commons.log.LogConfig;
|
||||
@@ -189,6 +190,10 @@ public class TinyEncryptMain {
|
||||
if (tinyEncryptArgs.showInWindow) {
|
||||
EncryptedFileUtil.decryptInWindow(config, f);
|
||||
result = false; // do not delete file
|
||||
} else if (tinyEncryptArgs.digest) {
|
||||
Bytes sha256 = EncryptedFileUtil.decryptAndDigest(config, f);
|
||||
log.info(sha256.asHex() + " - " + f);
|
||||
result = false; // do not delete file
|
||||
} else {
|
||||
result = EncryptedFileUtil.decryptFile(config, f);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.hatter.tools.tinyencrypt.config;
|
||||
|
||||
public class TinyEncryptConstant {
|
||||
public static final String VERSION = "0.3.3";
|
||||
public static final String VERSION = "0.3.4";
|
||||
|
||||
public static final String ENC_FILE_EXT = ".tinyenc";
|
||||
}
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
package me.hatter.tools.tinyencrypt.encrypt;
|
||||
|
||||
import me.hatter.tools.commons.assertion.AssertUtil;
|
||||
import me.hatter.tools.commons.bytes.Bytes;
|
||||
import me.hatter.tools.commons.io.DefaultRollCounter;
|
||||
import me.hatter.tools.commons.io.DigestOutputStream;
|
||||
import me.hatter.tools.commons.io.IOUtil;
|
||||
import me.hatter.tools.commons.log.LogTool;
|
||||
import me.hatter.tools.commons.log.LogTools;
|
||||
import me.hatter.tools.commons.security.crypt.CryptInputStream;
|
||||
import me.hatter.tools.commons.security.crypt.CryptOutputStream;
|
||||
import me.hatter.tools.commons.security.digest.Digests;
|
||||
import me.hatter.tools.commons.tlv.Tlv;
|
||||
import me.hatter.tools.commons.tlv.TlvUtil;
|
||||
import me.hatter.tools.tinyencrypt.config.TinyEncryptConfig;
|
||||
import me.hatter.tools.tinyencrypt.config.TinyEncryptConstant;
|
||||
import me.hatter.tools.tinyencrypt.win.SwingWindow;
|
||||
import me.hatter.tools.tinyencrypt.util.NilOutputStream;
|
||||
import me.hatter.tools.tinyencrypt.util.SwingWindow;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -48,6 +52,12 @@ public class EncryptedFileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Bytes decryptAndDigest(TinyEncryptConfig config, File file) {
|
||||
DigestOutputStream outputStream = new DigestOutputStream(new NilOutputStream(), Digests.sha256());
|
||||
decryptToOutputStream(config, file, outputStream);
|
||||
return outputStream.digest();
|
||||
}
|
||||
|
||||
public static void decryptInWindow(TinyEncryptConfig config, File file) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
decryptToOutputStream(config, file, baos);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.hatter.tools.tinyencrypt.win;
|
||||
package me.hatter.tools.tinyencrypt.util;
|
||||
|
||||
import me.hatter.tools.commons.classloader.ClassLoaderUtil;
|
||||
import me.hatter.tools.commons.io.RResource;
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.hatter.tools.tinyencrypt.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class NilOutputStream extends OutputStream {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte b[]) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte b[], int off, int len) throws IOException {
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.hatter.tools.tinyencrypt.win;
|
||||
package me.hatter.tools.tinyencrypt.util;
|
||||
|
||||
import me.hatter.tools.commons.string.StringUtil;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.hatter.tools.tinyencrypt.win;
|
||||
package me.hatter.tools.tinyencrypt.util;
|
||||
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
Reference in New Issue
Block a user