passforios-gopenpgp/subtle/subtle_test.go
wussler 54f45d0471
Openpgp security update (V2) (#31)
* Change keyring unlock functionalities

* Add keyring#Lock, keyring#CheckIntegrity, tests

* Update helpers, fix bugs

* Update go.mod with ProtonMail/crypto commit

* Change key management system

* Clear keys from memory + tests

* Create SessionKey with direct encryption for datapackets. Move symmetrickey to password.

* Fix upstream dependencies

* Update module to V2, documentation

* Add linter

* Add v2 folder to .gitignore

* Minor changes to KeyID getters

* Remove old changelog

* Improve docs, remove compilation script
2019-12-27 19:35:43 +01:00

32 lines
1.1 KiB
Go

package subtle
import (
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSubtle_EncryptWithoutIntegrity(t *testing.T) {
key, _ := hex.DecodeString("9469cccfc8a8d005247f39fa3e5b35a97db456cecf18deac6d84364d0818d763")
plaintext := []byte("some plaintext")
iv, _ := hex.DecodeString("c828f258a76aad7bc828f258a76aad7b")
ciphertext, _ := EncryptWithoutIntegrity(key, plaintext, iv)
assert.Exactly(t, "14697192f7e112fc88d83380693f", hex.EncodeToString(ciphertext))
}
func TestSubtle_DecryptWithoutIntegrity(t *testing.T) {
key, _ := hex.DecodeString("9469cccfc8a8d005247f39fa3e5b35a97db456cecf18deac6d84364d0818d763")
ciphertext, _ := hex.DecodeString("14697192f7e112fc88d83380693f")
iv, _ := hex.DecodeString("c828f258a76aad7bc828f258a76aad7b")
plaintext, _ := DecryptWithoutIntegrity(key, ciphertext, iv)
assert.Exactly(t, "some plaintext", string(plaintext))
}
func TestSubtle_DeriveKey(t *testing.T) {
salt, _ := hex.DecodeString("c828f258a76aad7b")
dk, _ := DeriveKey("some password", salt, 32768)
assert.Exactly(t, "9469cccfc8a8d005247f39fa3e5b35a97db456cecf18deac6d84364d0818d763", hex.EncodeToString(dk))
}