feat: add pgp finterprint
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package me.hatter.tools.tinyencrypt;
|
package me.hatter.tools.tinyencrypt;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import me.hatter.tools.commons.bytes.ByteUtil;
|
||||||
import me.hatter.tools.commons.bytes.Bytes;
|
import me.hatter.tools.commons.bytes.Bytes;
|
||||||
import me.hatter.tools.commons.exception.JumpOutException;
|
import me.hatter.tools.commons.exception.JumpOutException;
|
||||||
import me.hatter.tools.commons.io.RFile;
|
import me.hatter.tools.commons.io.RFile;
|
||||||
@@ -95,7 +96,10 @@ public class TinyEncryptMain {
|
|||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
sb.append("File version: ").append(meta.getVersion()).append("\n");
|
sb.append("File version: ").append(meta.getVersion()).append("\n");
|
||||||
if (meta.getFileLength() != null) {
|
if (meta.getFileLength() != null) {
|
||||||
sb.append("File size: ").append(meta.getFileLength()).append("\n");
|
sb.append("File size: ").append(meta.getFileLength())
|
||||||
|
.append(" (")
|
||||||
|
.append(ByteUtil.formatBytes(meta.getFileLength()))
|
||||||
|
.append(")\n");
|
||||||
}
|
}
|
||||||
if (meta.getFileLastModified() != null) {
|
if (meta.getFileLastModified() != null) {
|
||||||
sb.append("Last modified: ")
|
sb.append("Last modified: ")
|
||||||
@@ -110,6 +114,11 @@ public class TinyEncryptMain {
|
|||||||
} else {
|
} else {
|
||||||
sb.append("PGP envelop: NO\n");
|
sb.append("PGP envelop: NO\n");
|
||||||
}
|
}
|
||||||
|
if (StringUtil.isNotBlank(meta.getPgpFingerprint())) {
|
||||||
|
sb.append("PGP fingerprint: ")
|
||||||
|
.append(meta.getPgpFingerprint())
|
||||||
|
.append("\n");
|
||||||
|
}
|
||||||
sb.append("Agent: ").append(meta.getUserAgent());
|
sb.append("Agent: ").append(meta.getUserAgent());
|
||||||
if (StringUtil.isNotBlank(meta.getComment())) {
|
if (StringUtil.isNotBlank(meta.getComment())) {
|
||||||
sb.append("Comment: ").append(meta.getComment()).append("\n");
|
sb.append("Comment: ").append(meta.getComment()).append("\n");
|
||||||
|
|||||||
@@ -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.7";
|
public static final String VERSION = "0.3.8";
|
||||||
|
|
||||||
public static final String ENC_FILE_EXT = ".tinyenc";
|
public static final String ENC_FILE_EXT = ".tinyenc";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class TinyEncryptMeta {
|
|||||||
private String userAgent;
|
private String userAgent;
|
||||||
private String comment;
|
private String comment;
|
||||||
private String pgpEnvelop;
|
private String pgpEnvelop;
|
||||||
|
private String pgpFingerprint;
|
||||||
private String envelop;
|
private String envelop;
|
||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
private byte[] dataKey;
|
private byte[] dataKey;
|
||||||
@@ -56,6 +57,14 @@ public class TinyEncryptMeta {
|
|||||||
this.pgpEnvelop = pgpEnvelop;
|
this.pgpEnvelop = pgpEnvelop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPgpFingerprint() {
|
||||||
|
return pgpFingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPgpFingerprint(String pgpFingerprint) {
|
||||||
|
this.pgpFingerprint = pgpFingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
public String getEnvelop() {
|
public String getEnvelop() {
|
||||||
return envelop;
|
return envelop;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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.network.HttpRequest;
|
import me.hatter.tools.commons.network.HttpRequest;
|
||||||
import me.hatter.tools.commons.os.OSUtil;
|
import me.hatter.tools.commons.os.OSUtil;
|
||||||
|
import me.hatter.tools.commons.security.digest.Digests;
|
||||||
import me.hatter.tools.commons.security.key.KeyUtil;
|
import me.hatter.tools.commons.security.key.KeyUtil;
|
||||||
import me.hatter.tools.commons.security.random.RandomTool;
|
import me.hatter.tools.commons.security.random.RandomTool;
|
||||||
import me.hatter.tools.commons.security.rsa.RSAUtil;
|
import me.hatter.tools.commons.security.rsa.RSAUtil;
|
||||||
@@ -101,6 +102,7 @@ public class TinyEncryptMetaUtil {
|
|||||||
if (pgpEncryptPublicKey instanceof RSAPublicKey) {
|
if (pgpEncryptPublicKey instanceof RSAPublicKey) {
|
||||||
byte[] pgpEnvelop = RSAUtil.encrypt((RSAPublicKey) pgpEncryptPublicKey, dataKey);
|
byte[] pgpEnvelop = RSAUtil.encrypt((RSAPublicKey) pgpEncryptPublicKey, dataKey);
|
||||||
tinyEncryptMeta.setPgpEnvelop(Base64.getEncoder().encodeToString(pgpEnvelop));
|
tinyEncryptMeta.setPgpEnvelop(Base64.getEncoder().encodeToString(pgpEnvelop));
|
||||||
|
tinyEncryptMeta.setPgpFingerprint(Digests.sha256().digest(pgpEncryptPublicKey.getEncoded()).asHex());
|
||||||
} else {
|
} else {
|
||||||
log.warn("PGP encrypt public key is not RSAPublicKey: " + pgpEncryptPublicKey.getClass());
|
log.warn("PGP encrypt public key is not RSAPublicKey: " + pgpEncryptPublicKey.getClass());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user