forked from cloudfoundry-community/rds-broker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
52 lines (40 loc) · 1.16 KB
/
helpers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"crypto/aes"
"testing"
)
func TestEncryption(t *testing.T) {
msg := "Very secure message"
key := "12345678901234567890123456789012"
iv := GenerateIv(aes.BlockSize)
encrypted, _ := Encrypt(msg, key, iv)
if encrypted == msg {
t.Error("encrypted and original can't be the same")
}
decrypted, _ := Decrypt(encrypted, key, iv)
if decrypted != msg {
t.Error("decrypted should be the same as the original")
}
}
func TestIvChangesEncryption(t *testing.T) {
msg := "Very secure message"
key := "12345678901234567890123456789012"
iv1 := GenerateIv(aes.BlockSize)
iv2 := GenerateIv(aes.BlockSize)
encrypted1, _ := Encrypt(msg, key, iv1)
encrypted2, _ := Encrypt(msg, key, iv2)
if encrypted1 == encrypted2 {
t.Error("different ivs should return different strings")
}
}
func TestKeyChangesEncryption(t *testing.T) {
msg := "Very secure message"
key1 := "12345678901234567890123456789012"
key2 := "21098765432109876543210987654321"
iv := GenerateIv(aes.BlockSize)
encrypted1, _ := Encrypt(msg, key1, iv)
encrypted2, _ := Encrypt(msg, key2, iv)
if encrypted1 == encrypted2 {
t.Error("different ivs should return different strings")
}
}