38 lines
1 KiB
Go
38 lines
1 KiB
Go
// Copyright (C) 2019 Marius Schellenberger
|
|
|
|
package crypto
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/base64"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
text = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
|
|
cipher = "kkU4cAJeNmbFGaZFdubxFzUPfo/YNu3y02vKOD97mh48hJshRsBTbAkMo6TCq2yre89zcr54ZY6olAohOqSZAux5cpowHJQ1Hj7YDq+xAjWybERhApYTvhc283DW48Fc5usXmxoWbcqQ1eBl+QRC/RHBUO2qJ0p/MBu6sI2+nCu8z4ZLRqkh6JoMcLekYrKp6Tn34gaGgWi0ElSkD/uJzQmt3dqGHu5Hufj9MzzZlezzIHI3qzKFUaOKwFtLyoPBO2V6liMYCn2yxGWpsJPJQjvbcg=="
|
|
pass = "SecurePassword123"
|
|
)
|
|
|
|
func TestEncrypt(t *testing.T) {
|
|
buf := new(bytes.Buffer)
|
|
err := Encrypt([]byte(pass), []byte(text), buf)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestDecrypt(t *testing.T) {
|
|
buf := new(bytes.Buffer)
|
|
src, err := base64.StdEncoding.DecodeString(cipher)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = Decrypt([]byte(pass), src, buf)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if buf.String() != text {
|
|
t.Error("decrypted text does not match")
|
|
}
|
|
}
|