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