worstcrypto

command module
v0.0.0-...-ad5b1a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

README

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
  • RSA

    • Key generation with variable key length
    • Encryption & Decryption with OAEP (optimal asymmetric encryption padding)
    • Encryption & Decryption with no padding algorithm (textbook RSA, insecure)
    • Conversion of keys from and to the DER format
  • AES

    • Key Schedule
    • Encryption & Decryption of individual blocks
  • Scriptable command line utility

  • Easy-to-use API

  • Self-documenting code

Compilation

  1. Install Go on your computer
  2. Clone the repository
  3. Change to the correct directory in a terminal
  4. Execute one of these commands:
    1. To compile the command into an executable, run go build -o ./dist/ ./cmd/rsa/, you can then run the executable in the dist folder
    2. 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
  1. Import gitlab.kahveci-sw.de/ykahveci/worstcrypto/pkg/rsa in your Go program
  2. 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/.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package cipher provides a common interface for symmetric ciphers.
Package cipher provides a common interface for symmetric ciphers.
cmd
aes
rsa
internal
jwt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL