github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/utils/secret.go (about)

     1  package utils
     2  
     3  import (
     4  	"crypto/rand"
     5  	"io"
     6  
     7  	"github.com/jxskiss/base62"
     8  )
     9  
    10  func RandomSecret() string {
    11  	// 256 bit secret
    12  	buf := make([]byte, 32)
    13  	_, err := io.ReadFull(rand.Reader, buf)
    14  	// cannot error
    15  	if err != nil {
    16  		panic("could not read random")
    17  	}
    18  	return base62.EncodeToString(buf)
    19  }