模块介绍
使用 aes 对称解密算法 进行加密、解密,当前包使用的是 密码分组链(CBC) 模式。
方法说明
| 方法 | 说明 |
|---|---|
| aes.New(key, iv).Encrypt(encryptStr string) | 加密 |
| aes.New(key, iv).Decrypt(decryptStr string) | 解密 |
测试用例
func TestEncrypt(t *testing.T) {t.Log(New(key, iv).Encrypt("123456"))}func TestDecrypt(t *testing.T) {t.Log(New(key, iv).Decrypt("GO-ri84zevE-z1biJwfQPw=="))}
基准报告
func BenchmarkEncryptAndDecrypt(b *testing.B) {b.ResetTimer()aes := New(key, iv)for i := 0; i < b.N; i++ {encryptString, _ := aes.Encrypt("123456")aes.Decrypt(encryptString)}}// 输出goos: darwingoarch: amd64pkg: github.com/xinliangnote/go-gin-api/pkg/aesBenchmarkEncryptAndDecryptBenchmarkEncryptAndDecrypt-12 1219897 963 ns/opPASSProcess finished with exit code 0
