-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (40 loc) · 1.36 KB
/
main.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
package main
import (
"crypto/rand"
λ "github.com/4thel00z/lambda/v1"
"io"
"strings"
)
var (
loremIpsum = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.`
loremIpsumReader = strings.NewReader(loremIpsum)
)
func getRandomKey() []byte {
key := make([]byte, 32)
_, err := rand.Read(key)
if err != nil {
panic(err)
}
return key
}
func main() {
key := getRandomKey()
if λ.Read(loremIpsumReader).EncryptAES(key).DecryptAES(key).UnwrapString() != loremIpsum {
panic("encryption and decryption doesn't work")
}
// test for random payload and key that enc & decryption works fine
for i := 0; i < 10; i++ {
key = getRandomKey()
o := λ.Read(io.LimitReader(rand.Reader, 1024))
text := o.UnwrapString()
if o.EncryptAES(key).DecryptAES(key).UnwrapString() != text {
panic("encryption and decryption doesn't work")
}
}
}