这是一个块加密,固定Key,固定IV,加解密长度一致,不传IV.所以同一白文加密后,密文是一致的.
如需密文传输随机IV,请使用 encrypt 的encrypt的块加密, 同一白文加密后,密文是不一样的
go get github.com/things-labs/aesext
import "github.com/things-labs/aesext"
package main
import (
"bytes"
"github.com/things-labs/aesext"
)
func main() {
key, salt := []byte("iamakey"), []byte("iamasalt")
bc, err := aesext.New(key, salt)
if err != nil {
panic(err)
}
want := []byte("iamaplaintext")
cipherText, err := bc.Encrypt(want)
if err != nil {
panic(err)
}
got, err := bc.Decrypt(cipherText)
if err != nil {
panic(err)
}
ok := bytes.Equal(got, want)
if !ok {
panic("invalid encrypt and decrypt")
}
}
This project is under MIT License. See the LICENSE file for the full license text.