Public/private key encryption/decryption demo using the RSA cryptosystem.
Requirements
To build, run:
mvn package
The ppcrypt.jar
file will be stored in the target
directory.
Run:
java -jar ppcrypt.jar
Append -h
or --help
to get a list of all available options:
java -jar ppcrypt.jar -h
All available options are:
-d,--decrypt
-e,--encrypt
-h,--help print this help message and exit
-i,--input <file> input file
-k,--key <file> public-/private-key file for encryption/decryption
-o,--output <file> output file
-v,--version print version info and exit
To generate a 1024-bit RSA key-pair, run:
openssl genrsa -out private.pem 1024
openssl pkcs8 -topk8 -inform PEM -outform DER -in private.pem -out private.der -nocrypt
openssl rsa -in private.pem -pubout -outform DER -out public.der
The public-key will be stored in public.der
, the private-key in private.der
.
To encrypt a message stored in message.txt
into secret.txt
using the
public-key, run:
java -jar ppcrypt.jar --encrypt --key public.der --input message.txt --output secret.txt
or short:
java -jar ppcrypt.jar -e -k public.der -i message.txt -o secret.txt
To decrypt a secret stored in secret.txt
back to revealed.txt
using the
private-key, run:
java -jar ppcrypt.jar --decrypt --key private.der --input secret.txt --output revealed.txt
or short:
java -jar ppcrypt.jar -d -k private.der -i secret.txt -o revealed.txt
This software is distributed under the terms of the GNU General Public License v3.