You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1014 B

  1. package xsalsa20symmetric
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/tendermint/crypto"
  7. "golang.org/x/crypto/bcrypt"
  8. )
  9. func TestSimple(t *testing.T) {
  10. crypto.MixEntropy([]byte("someentropy"))
  11. plaintext := []byte("sometext")
  12. secret := []byte("somesecretoflengththirtytwo===32")
  13. ciphertext := EncryptSymmetric(plaintext, secret)
  14. plaintext2, err := DecryptSymmetric(ciphertext, secret)
  15. require.Nil(t, err, "%+v", err)
  16. assert.Equal(t, plaintext, plaintext2)
  17. }
  18. func TestSimpleWithKDF(t *testing.T) {
  19. crypto.MixEntropy([]byte("someentropy"))
  20. plaintext := []byte("sometext")
  21. secretPass := []byte("somesecret")
  22. secret, err := bcrypt.GenerateFromPassword(secretPass, 12)
  23. if err != nil {
  24. t.Error(err)
  25. }
  26. secret = crypto.Sha256(secret)
  27. ciphertext := EncryptSymmetric(plaintext, secret)
  28. plaintext2, err := DecryptSymmetric(ciphertext, secret)
  29. require.Nil(t, err, "%+v", err)
  30. assert.Equal(t, plaintext, plaintext2)
  31. }