basic common app packages
This commit is contained in:
35
crypto/encryption_test.go
Normal file
35
crypto/encryption_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewEncryptionKey(t *testing.T) {
|
||||
if key, err := NewEncryptionKey(32); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
fmt.Println(key)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptDecrypt(t *testing.T) {
|
||||
text := "Hellp World!"
|
||||
key := "Laumw6mvWwrc8Q1SZQYCdiVr/dDBpjDdpaI6v4WvWSw="
|
||||
|
||||
// crypt
|
||||
crypted, err := Encrypt(key, text)
|
||||
if err != nil {
|
||||
t.Errorf("Encrypt failed: %v", err)
|
||||
}
|
||||
|
||||
decrypted, err := Decrypt(key, crypted)
|
||||
if err != nil {
|
||||
t.Errorf("Decrypt failed: %v", err)
|
||||
}
|
||||
|
||||
if string(decrypted) != text {
|
||||
t.Errorf("Decrypted text does not match original")
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user