AsymCrypt optimize + Symcrypt creation

This commit is contained in:
ycc
2022-09-18 21:17:28 +02:00
parent 01aec23f76
commit 35fa29f5b9
9 changed files with 199 additions and 22 deletions

View File

@ -29,28 +29,29 @@ func TestGetKey(t *testing.T) {
//}
}
func TestEncryptDecrypt(t *testing.T) {
func TestAsymEncryptDecrypt(t *testing.T) {
kp := NewKeyPair()
foo := "totoaimelesfrites!"
encMess, err := Encrypt(kp.Public, []byte(foo))
foo := []byte("!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~")
encMess, err := AsymEncrypt(kp.Public, foo)
if err != nil {
log.Println(err.Error())
}
decMess, err2 := Decrypt(kp.Private, encMess)
println("len enc:", len(encMess))
decMess, err2 := AsymDecrypt(kp.Private, encMess)
if err2 != nil {
log.Println(err2.Error())
}
assert.Equal(t, foo, decMess, "The two messages should be the same.")
}
func TestEncryptDecryptSigned(t *testing.T) {
func TestAsymEncryptDecryptSigned(t *testing.T) {
kp := NewKeyPair()
foo := "totoaimelesfrites!"
encMess, sign, err := EncryptAndSign(kp.Public, kp.Private, []byte(foo))
foo := "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~"
encMess, sign, err := AsymEncryptAndSign(kp.Public, kp.Private, []byte(foo))
if err != nil {
log.Println(err.Error())
}
decMess, err2 := DecryptAndCheck(kp.Private, kp.Public, encMess, sign)
decMess, err2 := AsymDecryptAndCheck(kp.Private, kp.Public, encMess, sign)
if err2 != nil {
log.Println(err2.Error())
}