tago

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 6 Imported by: 2

README

Tago Use tago to encrypt any classified text with secured random secret keys for the mixture to formulate the encrypted text and able to decrypt it with the same secret key when you need to extract the whole classified text back to a normal phrase.

Installation

go get -u github.com/itrepablik/tago

Usage

package main

import (
	"fmt"
	"log"

	"github.com/itrepablik/tago"
)

func main() {
	// Generate a secure random salt
	secretKey, err := tago.GenerateSecretKey(32)
	if err != nil {
		log.Fatalf("error generating secret key: %s", err)
	}

	// ************************************************************************
	// Encrypt a string
	// ************************************************************************
	plaintext := "Hello World!"
	ciphertext, iv, err := tago.Encrypt(plaintext, string(secretKey))
	if err != nil {
		log.Fatalf("error encrypting string: %s", err)
	}
	if ciphertext == plaintext {
		log.Fatalln("plaintext and ciphertext should not be the same")
	}

	fmt.Printf("plaintext: %s\nciphertext: %s\niv: %s", plaintext, ciphertext, iv)

	// ************************************************************************
	// Decrypt a ciphertext
	// ************************************************************************
	decrypted, err := tago.Decrypt(ciphertext, string(secretKey), iv)
	if err != nil {
		log.Fatalf("error decrypting string: %s", err)
	}
	if decrypted != plaintext {
		log.Fatalln("plaintext and decrypted should be the same")
	}

	fmt.Println("\ndecrypted:", decrypted)
}

Subscribe to Maharlikans Code Youtube Channel:

Please consider subscribing to my Youtube Channel to recognize my work on any of my tutorial series. Thank you so much for your support! https://www.youtube.com/c/MaharlikansCode?sub_confirmation=1

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(text, secretKey string, iv []byte) (string, error)

Decrypt is the decryptor of the classified text, remember to use the same secret key

func Encrypt

func Encrypt(text, secretKey string) (string, []byte, error)

Encrypt is the encryptor of the classified text, remember to use the same secret key Save the IV somewhere safe, it will be used to decrypt the text

func GenerateSecretKey added in v1.0.4

func GenerateSecretKey(byteSize int) (string, error)

GenerateSecretKey is the function to generate a secured random secret key either 16, 24, or 32 bytes to select AES-128, AES-192 or AES-256

Types

This section is empty.

Jump to

Keyboard shortcuts

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