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.

40 lines
929 B

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