github.com/chain5j/chain5j-pkg@v1.0.7/crypto/scrypt/passphrase_test.go (about)

     1  package scrypt
     2  
     3  import (
     4  	"encoding/hex"
     5  	"fmt"
     6  	"testing"
     7  )
     8  
     9  const (
    10  	veryLightScryptN = 2
    11  	veryLightScryptP = 1
    12  )
    13  
    14  func TestEncryptKey(t *testing.T) {
    15  	prvKey, _ := hex.DecodeString("587ca4a15bc4d239cfba433dda03366506e99ecd2c529216eb3168b3e7806257")
    16  	k := &Key{
    17  		// Address:    addr,
    18  		PrivateKey: prvKey,
    19  	}
    20  	keyJson, err := EncryptKey(k, "123456", veryLightScryptN, veryLightScryptP)
    21  	if err != nil {
    22  		t.Errorf("test: failed to recrypt key %v", err)
    23  	}
    24  	fmt.Println(string(keyJson))
    25  
    26  	key, err := DecryptKey(keyJson, "123456")
    27  	if err != nil {
    28  		t.Errorf("test: failed to recrypt key %v", err)
    29  	}
    30  	prvKey1 := hex.EncodeToString(key.PrivateKey)
    31  	fmt.Println("prvKey1", prvKey1)
    32  }