Skip to content

Latest commit

 

History

History
94 lines (69 loc) · 3.58 KB

README.md

File metadata and controls

94 lines (69 loc) · 3.58 KB

goAES

Simple package for AES encryption and decryption. It use sha256 for hash the secret key. Based on CTR

BuildStatus ReportCard Go Coverage Codacy Badge codebeat badge Maintainability GolangCI Open Source Helpers

GoDoc FOSSA Status MIT license

Usage

Encryption

package main

import (
	"fmt"
	"log"

	goaes "github.com/syronz/goAES"
)

func main() {
	aes, err := goaes.New().Key("secret key").IV("iv is 16 char!!!").Build()
	if err != nil {
		log.Fatal(err)
	}

	term := "Hello"
	encrypted := aes.Encrypt(term)

	fmt.Printf("Encryption of %q is %q \n", term, encrypted)
}

output:

Encryption of "Hello" is "257d85d55b" 

Decryption

Default length is 100 character, in case the orginal term is more than 100 in AES decryption, you shold mention the Length in the build.

package main

import (
	"fmt"
	"log"

	goaes "github.com/syronz/goAES"
)

func main() {
	aes, err := goaes.New().Key("secret key").IV("iv is 16 char!!!").Build()
	if err != nil {
		log.Fatal(err)
	}

	encrypted := "257d85d55b"
	decrypted := aes.Decrypt(encrypted)

	fmt.Printf("Decryption of %q is %q \n", encrypted, decrypted)
}

output:

Decryption of "257d85d55b" is "Hello" 

Note

In case of the length of decrypted word is more than 100, we should use .Length(int) like here. Extra chars will be trimmed

aes, err := goaes.New().Key("secret key").IV("iv is 16 char!!!").Length(10000).Build()

Online test

By going to the gchq.github.io/CyberChef you can test it manually

License

FOSSA Status