Simple package for AES encryption and decryption. It use sha256 for hash the secret key. Based on CTR
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"
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"
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()
By going to the gchq.github.io/CyberChef you can test it manually