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.

42 lines
939 B

  1. package crypto
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "golang.org/x/crypto/bcrypt"
  7. )
  8. func TestSimple(t *testing.T) {
  9. MixEntropy([]byte("someentropy"))
  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. MixEntropy([]byte("someentropy"))
  19. plaintext := []byte("sometext")
  20. secretPass := []byte("somesecret")
  21. secret, err := bcrypt.GenerateFromPassword(secretPass, 12)
  22. if err != nil {
  23. t.Error(err)
  24. }
  25. secret = Sha256(secret)
  26. ciphertext := EncryptSymmetric(plaintext, secret)
  27. plaintext2, err := DecryptSymmetric(ciphertext, secret)
  28. require.Nil(t, err, "%+v", err)
  29. assert.Equal(t, plaintext, plaintext2)
  30. }