2014-01-16 21 views

回答

20

要生成的64個隨機字節切片:

package main 

import "crypto/rand" 

func main() { 
    key := make([]byte, 64) 

    _, err := rand.Read(key) 
    if err != nil { 
     // handle error here 
    } 
} 

演示here

+0

如何將其轉換爲字符串格式,以便將其保存在環境變量中? – Lee

+0

@lee隨機字節的Base64編碼應該這樣做(https://gobyexample.com/base64-encoding) – Alex

+0

@lee更新了演示。在那裏檢查。 – Agis