-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrypto_test.go
66 lines (55 loc) · 1.94 KB
/
crypto_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2016 Tristan Colgate-McFarlane
//
// This file is part of gostikkit.
//
// radia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// radia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with radia. If not, see <http://www.gnu.org/licenses/>.
package gostikkit
import (
"encoding/base64"
"testing"
)
var plain = `AAA`
var key = `23XIKa66q3fM9hfxxPvIaKaSK584kolA`
var b64 = `U2FsdGVkX19843ZgwE2B9A88goyvERASPauARUgY9HI=`
var lzplain = ``
func TestCrypt1(t *testing.T) {
//password := "example"
password := key
plaintext := "exampleplaintext"
dec := string(decrypt(encrypt(plaintext, password), password))
if plaintext != dec {
t.Fatalf("failed:\nwanted: %v\n got: %v\n", plaintext, dec)
}
}
func TestDecrypt1(t *testing.T) {
// CryptoJS.AES.decrypt("U2FsdGVkX1+SPCDRNc9kniYWDtYoGS3h/M6xRv2RuYk=","12345678901234567890123456789012").toString(CryptoJS.enc.Utf8)
ciphertext, err := base64.StdEncoding.DecodeString("U2FsdGVkX1+SPCDRNc9kniYWDtYoGS3h/M6xRv2RuYk=")
if err != nil {
t.Fatalf("%v", err)
}
password := "12345678901234567890123456789012"
expected := "hello"
plaintext := decrypt(ciphertext, password)
if string(plaintext) != expected {
t.Fatalf("Wrong decryption result:\n got %v\n expected %v\n", string(plaintext), expected)
}
}
func TestCryptNoSalt(t *testing.T) {
password := key
plaintext := "exampleplaintext"
dec := string(decrypt(encrypt(plaintext, password), password))
if plaintext != dec {
t.Fatalf("failed:\nwanted: %v\n got: %v\n", plaintext, dec)
}
}