gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/x509/utils_test.go (about)

     1  package x509
     2  
     3  import (
     4  	"encoding/hex"
     5  	"fmt"
     6  	"gitee.com/ks-custle/core-gm/utils"
     7  	"github.com/stretchr/testify/assert"
     8  	"testing"
     9  )
    10  
    11  func TestWriteKeyToPemFile(t *testing.T) {
    12  	key, err := utils.GetRandomBytes(16)
    13  	if err != nil {
    14  		t.Fatal(err)
    15  	}
    16  	fmt.Printf("key in hex: %s\n", hex.EncodeToString(key))
    17  
    18  	pwd, err := utils.GetRandomBytes(32)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	err = WriteKeyToPemFile("testdata/key_16.pem", key, pwd)
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  
    28  	keyFromPemFile, err := ReadKeyFromPemFile("testdata/key_16.pem", pwd)
    29  	if err != nil {
    30  		return
    31  	}
    32  	fmt.Printf("keyFromPemFile in hex: %s\n", hex.EncodeToString(keyFromPemFile))
    33  
    34  	assert.Equal(t, key, keyFromPemFile)
    35  }
    36  
    37  func Test001(t *testing.T) {
    38  	num := 1 << 16
    39  	fmt.Println(num)
    40  	fmt.Println(num / 1024)
    41  }