-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_test.go
30 lines (27 loc) · 1.02 KB
/
example_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
package encrypt
import "fmt"
func ExampleEncrypt() {
text := "Two roads diverged in a yellow wood"
// 32 bytes
secretKey := []byte("1m!Cn25GW2frzDefg)^q2koE(4K2vIQX")
encrypted := Encrypt(secretKey, []byte(text))
fmt.Println(EncodeBase64(encrypted))
fmt.Println("sha1:", Sha1([]byte(text)))
// Output:
// pLJGOMRo4IxI/wAiLe5dhFYCiwcCMCpa80JzTunHBYY3S3q2E3YhiShGmVOHx55NENjwzAaSmsjlhDlc7wHWQQ==
// sha1: 97d2ce306525e5036b6a39737d8ac415869f6e4c
}
func ExampleDecrypt() {
encrypted := "pLJGOMRo4IxI/wAiLe5dhFYCiwcCMCpa80JzTunHBYY3S3q2E3YhiShGmVOHx55NENjwzAaSmsjlhDlc7wHWQQ=="
text := "Two roads diverged in a yellow wood"
// 32 bytes
secretKey := []byte("1m!Cn25GW2frzDefg)^q2koE(4K2vIQX")
decrypt := Decrypt(secretKey, []byte(DecodeBase64(encrypted)))
fmt.Println(decrypt)
sha1 := Sha1([]byte(decrypt))
sha2 := Sha1([]byte(text))
fmt.Println("sha1:", sha1, "sha2:", sha2)
// Output:
// Two roads diverged in a yellow wood
// sha1: 97d2ce306525e5036b6a39737d8ac415869f6e4c sha2: 97d2ce306525e5036b6a39737d8ac415869f6e4c
}