utils/pcrypto: fix the bug of using aes

1. The aes IV needs to be unique, but not secure.
2. The key should be 16, 24 or 32 bytes.

Fixes #85.
This commit is contained in:
fatedier
2016-08-21 23:28:01 +08:00
parent 2b1c39e03d
commit c8e5096f48
3 changed files with 66 additions and 17 deletions

View File

@@ -24,7 +24,7 @@ var (
func init() {
pp = &Pcrypto{}
pp.Init([]byte("Hana"))
pp.Init([]byte("12234567890123451223456789012345321:wq"))
}
func TestEncrypt(t *testing.T) {
@@ -60,3 +60,18 @@ func TestCompression(t *testing.T) {
t.Fatalf("test compression error, from [%s] to [%s]", testStr, string(res))
}
}
func BenchmarkEncrypt(b *testing.B) {
testStr := "Test Encrypt!"
for i := 0; i < b.N; i++ {
pp.Encrypt([]byte(testStr))
}
}
func BenchmarkDecrypt(b *testing.B) {
testStr := "Test Encrypt!"
res, _ := pp.Encrypt([]byte(testStr))
for i := 0; i < b.N; i++ {
pp.Decrypt([]byte(res))
}
}