1 回答

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
sops.Tree.Encrypt
讓我們看看(a typo here in your code)的函數(shù)聲明。通過(guò)代碼,我們應(yīng)該分這幾步去做。
sops.Tree
使用 json 文件構(gòu)造一個(gè)實(shí)例。使用特定
Cipher
的加密。
請(qǐng)以這種方式嘗試自己。
下面代碼demo,用AES作為Cipher,sops只能用源碼接口加密total tree。
package main
import (
"fmt"
"go.mozilla.org/sops"
"go.mozilla.org/sops/aes"
"go.mozilla.org/sops/stores/json"
)
func main() {
/*
fileContent := []byte(`{
"secret": "strongPassword"
}`)
*/
fileContent, _ := ioutil.ReadFile("xxx.json")
encryptKey := []byte("0123456789012345") // length 16
branches, _ := (&json.Store{}).LoadPlainFile(fileContent)
tree := sops.Tree{Branches: branches}
r, err := tree.Encrypt(encryptKey, aes.NewCipher())
if err != nil {
panic(err)
}
fmt.Println(r)
}
- 1 回答
- 0 關(guān)注
- 113 瀏覽
添加回答
舉報(bào)