feat: v0.3.5, digest compares clear text file
This commit is contained in:
@@ -7,6 +7,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.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;
|
||||||
import me.hatter.tools.commons.security.key.PKType;
|
import me.hatter.tools.commons.security.key.PKType;
|
||||||
@@ -192,7 +193,19 @@ public class TinyEncryptMain {
|
|||||||
result = false; // do not delete file
|
result = false; // do not delete file
|
||||||
} else if (tinyEncryptArgs.digest) {
|
} else if (tinyEncryptArgs.digest) {
|
||||||
Bytes sha256 = EncryptedFileUtil.decryptAndDigest(config, f);
|
Bytes sha256 = EncryptedFileUtil.decryptAndDigest(config, f);
|
||||||
log.info(sha256.asHex() + " - " + f);
|
if (sha256 != null) {
|
||||||
|
log.info(sha256.asHex() + " - " + f);
|
||||||
|
File clearTextFile = EncryptedFileUtil.getDecryptFile(f);
|
||||||
|
if ((clearTextFile != null) && clearTextFile.exists()) {
|
||||||
|
Bytes clearTextSha256 = RFile.from(clearTextFile).digest(Digests.sha256());
|
||||||
|
if (clearTextSha256.equals(sha256)) {
|
||||||
|
log.info("Clear text file exists, and matches.");
|
||||||
|
} else {
|
||||||
|
String nfn = f.toString();
|
||||||
|
log.warn(clearTextSha256.asHex() + " - " + nfn.substring(0, nfn.length() - TinyEncryptConstant.ENC_FILE_EXT.length()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
result = false; // do not delete file
|
result = false; // do not delete file
|
||||||
} else {
|
} else {
|
||||||
result = EncryptedFileUtil.decryptFile(config, f);
|
result = EncryptedFileUtil.decryptFile(config, f);
|
||||||
|
|||||||
@@ -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.4";
|
public static final String VERSION = "0.3.5";
|
||||||
|
|
||||||
public static final String ENC_FILE_EXT = ".tinyenc";
|
public static final String ENC_FILE_EXT = ".tinyenc";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ public class EncryptedFileUtil {
|
|||||||
|
|
||||||
public static Bytes decryptAndDigest(TinyEncryptConfig config, File file) {
|
public static Bytes decryptAndDigest(TinyEncryptConfig config, File file) {
|
||||||
DigestOutputStream outputStream = new DigestOutputStream(new NilOutputStream(), Digests.sha256());
|
DigestOutputStream outputStream = new DigestOutputStream(new NilOutputStream(), Digests.sha256());
|
||||||
decryptToOutputStream(config, file, outputStream);
|
if (!decryptToOutputStream(config, file, outputStream)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return outputStream.digest();
|
return outputStream.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user