Files
tiny-encrypt-java/README.md
2023-04-01 16:45:04 +08:00

3.8 KiB

tiny-encrypt-java

Tiny encrypt implemented by Java

Config ~/.tinyencrypt_config.json:

{
  "ageRecipient": "age1***",
  "cardCli": "/Users/hatterjiang/.cargo/bin/card-cli",
  "pgpEncryptPublicKeyPem": "-----BEGIN PUBLIC KEY-----\n***\n-----END PUBLIC KEY-----",
  "turnOffEnvelop": false,
  "defaultKeyName": "prod_ec_key",
  "localPrivateKeyPemChallenge": "***",
  "localPrivateKeyPemEncrypted": "***",
  "localPublicKeyPem": "-----BEGIN PUBLIC KEY-----\n***\n-----END PUBLIC KEY-----"
}

Debug logging:

$ java -jar -Dcommons.log.debug=true tiny-encrypt.jar ...

Encrypt file:

$ tiny-encrypt -e test.txt 
[INFO] Start processing file: test.txt, 1 of 1
[INFO] Get data key from kms, key name: prod_ec_key, with sign: false ...
Encrypting, Processed: 12, Speed: 2.93KB/s
[INFO] Encrypt file success: test.txt

Skip envelop data key: --skip-envelop

Show encrypted file info:

$ tiny-encrypt -I test.txt.tinyenc 
[INFO] Tiny Encrypt File Info
File..............: test.txt.tinyenc
File size.........: 12 byte(s)
Enc file summary..: Version: 1.0, Agent: TinyEncrypt v0.5.1@MacOS
Last modified.....: Fri Feb 10 00:50:07 CST 2023
Enc file created..: Fri Feb 10 01:16:12 CST 2023
Envelops..........: KMS: YES, PGP: YES
PGP fingerprint...: de5a99c239a82adf039982cb6319abcb95f44cfc76a5027ae6f7819cfc5fde7c
Encrypted comment.: NO

Decrypt file:

$ tiny-encrypt -d test.txt.tinyenc 
[INFO] Start processing file: test.txt.tinyenc, 1 of 1
[INFO] Start: /Users/hatterjiang/.cargo/bin/card-cli
[INFO] Finished command
[INFO] Decrypt local private key success!
[INFO] Decrypt data key ...
Decrypting, Processed: 12, Speed: 3.91KB/s
[INFO] Decrypt file success: test.txt.tinyenc

Decrypt file with OpenPGP card:

$ tiny-encrypt -d --pgp test.txt.tinyenc 
[INFO] Start processing file: test.txt.tinyenc, 1 of 1
Input PGP user PIN: 
[INFO] Start: /Users/hatterjiang/.cargo/bin/card-cli
[INFO] Finished command
Decrypting, Processed: 12, Speed: 2.93KB/s
[INFO] Decrypt file success: test.txt.tinyenc

Create file from text window:

$ tiny-encrypt --create FILE

Show file in text window:

$ tiny-encrypt -d --show FILE.tinyenc

Edit file in text window:

$ tiny-encrypt -d --edit FILE.tinyenc

Use alias:

alias tiny-encrypt='java -jar ~/bin/tiny-encrypt.jar'
alias tiny-encrypt-debug='java -jar -Dcommons.log.debug=true ~/bin/tiny-encrypt.jar'

File ext: *.tinyenc

File format:

[TAG; 2 bytes; short; BE; Always 1]
[LENGTH; 4 bytes; int; BE]
[META; LENGTH bytes]
[ENCRYPTED_DATA; n bytes; AES/GCM]

Meta format:

Field Type Comment
version String Constant value: 1.0
created Long Created time, Unix Epoch, in millis
userAgent String User Agent, e.g. TinyEncrypt v0.6.0@MacOS
comment String Plain text comment
encryptedComment String Encrypted comment
envelop String KMS encrypted data key
pgpEnvelop String PGP Publickey encrypted data key
pgpFingerprint String Hex(Sha256(PGP Publickey))
ageEnvelop String Age encrypted data key
ageRecipient String Age recipient
ecdhEnvelop String ECDH encrypted data key
ecdhPoint String Ephemeral public key
nonce byte[] GCM nonce
fileLength Long File length
fileLastModified Long File last modified, Unix Epoch, in millis
compress Boolean Compressed or not