crypter
AES encryption and hashing of string data.
Install
go get github.com/MichailVestnik/crypter
Create new AES encrypter
const (
signature = "QAWSEDRFTGYHUJIKOLAZSXDCFVGBHNJM" // must by 32 bytes!
ivector = "vector"
salt = "SALT:SDR123"
data = "String Data"
)
crypt := crypter.New(signature, ivector, salt)
Encrypt and decrypt data
// encrypt data
encr, e := crypt.Encrypt(data)
if e != nil {
log.Fatal(e)
}
fmt.Printf("encrypted data: %v\n", encr)
// decrypt data
decr, e := crypt.Decrypt(encr)
if e != nil {
log.Fatal(e)
}
fmt.Printf("decrypted data: %v\n", decr)
Encrypt and decrypt data with hex
encr, e := crypt.Encrypt(data)
if e != nil {
log.Fatal(e)
}
fmt.Printf("encrypted data: %v\n", encr)
str := hex.EncodeToString(encr)
fmt.Printf("hex string: %v\n", str)
// decrypt data
bytes, e := hex.DecodeString(str)
if e != nil {
log.Fatal(e)
}
decr, e := crypt.Decrypt(bytes)
if e != nil {
log.Fatal(e)
}
fmt.Printf("decrypted data: %v\n", decr)
Hash
// hash with sha256
sha := crypt.SHA256(data)
fmt.Println(sha)
// hash with md5
md5 := crypt.MD5(data)
fmt.Println(md5)