github.com/deroproject/derosuite@v2.1.6-1.0.20200307070847-0f2e589c7a2b+incompatible/walletapi/cipher_test.go (about)

     1  package walletapi
     2  
     3  import "testing"
     4  import "crypto/sha256"
     5  
     6  // functional test whether  the wrappers are okay
     7  func Test_AEAD_Cipher(t *testing.T) {
     8  
     9  	var key = sha256.Sum256([]byte("test"))
    10  	var data = []byte("data")
    11  
    12  	encrypted, err := EncryptWithKey(key[:], data)
    13  
    14  	if err != nil {
    15  		t.Fatalf("AEAD cipher failed err %s", err)
    16  	}
    17  
    18  	//t.Logf("Encrypted data %x %s", encrypted, string(encrypted))
    19  
    20  	decrypted, err := DecryptWithKey(key[:], encrypted)
    21  	if err != nil {
    22  		t.Fatalf("AEAD cipher decryption failed, err %s", err)
    23  	}
    24  
    25  	if string(decrypted) != "data" {
    26  		t.Fatalf("AEAD cipher encryption/decryption failed")
    27  	}
    28  }