WorstCrypto
A go command line application and library that implements cryptographic algorithms (currently only RSA, maybe eventually SHA-256/512, AES and ChaCha20 soon), intended for educational purposes only.
Its API is heavily inspired by the standard library crypto API
YOU SHOULD NEVER EVER USE THIS IN PRODUCTION!
Use the standard library packages instead!
Features
Compilation
- Install Go on your computer
- Clone the repository
- Change to the correct directory in a terminal
- Execute one of these commands:
- To compile the command into an executable, run
go build -o ./dist/ ./cmd/rsa/
, you can then run the executable in the dist folder
- To execute the rsa command line utility, just use
go run ./cmd/rsa/
Usage
Command line utility
Key generation
You can generate a 4096-bit RSA keypair and write it to a file in PEM format like this:
./dist/rsa --action g --privkey private.pem --pubkey public.pem
You can optionally pass the number of bits you want the key to have:
./dist/rsa --action g --bits 3072 --privkey private.pem --pubkey public.pem
Encryption
You can encrypt a file using your newly generated public key, it will be output binary ciphertext with no metadata:
./dist/rsa --action e --pubkey public.pem --in message.txt --out encrypted.bin
Decryption
Here is how you can decrypt your encrypted file using the private key:
./dist/rsa --action d --privkey private.pem --in encrypted.bin --out message.txt
Library / Package
- Import
gitlab.kahveci-sw.de/ykahveci/worstcrypto/pkg/rsa
in your Go program
- Use the well-documented functions (Trust me, it's easy! Just look at the following example!)
Example
package main
import (
"crypto/sha512"
"fmt"
"gitlab.kahveci-sw.de/ykahveci/worstcrypto/pkg/rsa"
)
func main() {
// Key Generation made easy
priv := rsa.GenerateKeypair(4096)
pub := priv.Public()
// Encryption with OAEP
c, err := pub.EncryptOAEP([]byte("Hello World!"), sha512.New(), nil)
if err != nil {
panic(err)
}
// Decryption with OAEP
m, err := priv.DecryptOAEP(c, sha512.New(), nil)
if err != nil {
panic(err)
}
// Hello World!
fmt.Println(string(m))
}
License
WorstCrypto Copyright (C) 2022 Yunus Kahveci
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.