github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/util/crypt_test.go (about)

     1  // Copyright (c) 2019 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package util
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestEnc(t *testing.T) {
    15  	require := require.New(t)
    16  
    17  	data := []struct {
    18  		input string
    19  		key   string
    20  	}{
    21  		{"Foo", "Boo"},
    22  		{"Bar", "Car"},
    23  		{"Bar", ""},
    24  		{"", "Car"},
    25  		{"Long input with more than 16 characters", "Car"},
    26  	}
    27  	for _, d := range data {
    28  		enc, err := Encrypt([]byte(d.input), HashSHA256([]byte(d.key)))
    29  		require.NoError(err)
    30  
    31  		dec, err := Decrypt(enc, HashSHA256([]byte(d.key)))
    32  		require.NoError(err)
    33  
    34  		require.Equal(string(dec), d.input)
    35  	}
    36  }