gpt4 book ai didi

go - 替代 golang 中的 load_pem_private_key()

转载 作者:数据小太阳 更新时间:2023-10-29 03:19:59 25 4
gpt4 key购买 nike

我在 python 中有这段代码

privateKey = appAuth["privateKey"]
passphrase = appAuth["passphrase"]

from cryptography.hazmat.primitives.serialization import load_pem_private_key
key = load_pem_private_key(
data=privateKey.encode('utf8'),
password=passphrase.encode('utf8'),
backend=default_backend(),)

我想在 golang 中复制它。基本上我有这个:-

"appAuth": {
"publicKeyID": "2qwqckds",
"privateKey": "-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0AeQwwDgQIkkci4MFCUtsCAggA\nMBQGCCqGSIb3DQMHBAjyW3BUgbqg9ASCBMjEpz/mhgRXFKkFpSL4SAq7YLxYzO7H\nYfbisbcsrN4C1wAiXpT4FMBuGnHzRrm/slu+DnTdbsKrg2SxiyW3Zy5FtBfYGPHF\nYim4It2lPywMHHS62b2qXdIicW4pfst/eqeisLpl0bBTR7UYbxr6vpsVFKrGkjEI\n8+VtADGgm6ORH975NBZiLrCEO2aLOfeXlQrdWHcNEB46emvoasBKRZ0bUTxUqKN9\negGPprpfEb7yp0UoJZayYpxcZOSEuM42jXiGELQ9qM7xeADlTP5rbw2d6r/Hbr67\nvyDk2fydvRra4XlbDgeKfiD71OaetoyF8o07Zo4VJegdZnHYW7BW2kXuD5uCiNYI\nWN3l9TpX8i6FU1i++NidH80t5cHAHlhBc2v0if5g8TlmRDarOo6pX8d2KLV98V7F\n7iWmS9vHtyZZvIgaWDchQ+fVQ2ZS6KCRGnGipxkmGyDXnPcx60YPiN9NxCmKs0ji\n8e7xtM+QXzYPWF/rUQh/YmISYGoktOj2XMxXmpNXdpcHFIWEbuW0LuWhV++4WrnO\nly9Vc3PwnHi5KE+IzgoOtgPkxDkr664fd5H0DD3RD1ytWuMW0rtKMr8jx/vRUkzM\n+yzGo0UMe4XW0M0Xcrpq+o+0NBwa05xGA6vlrerMuLcsY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ang 中,到目前为止我已经尝试过这个:-

block, _ := pem.Decode([]byte(privateKey)) \\ privateKey is a string
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)

但它不起作用。请帮忙。

最佳答案

在 go 中解密加密的 pkcs8 key (问题中提到了此类 key 的示例)有一个很棒的图书馆https://github.com/youmark/pkcs8/ .

import "github.com/youmark/pkcs8"
block, _ := pem.Decode([]byte(config.BoxAppSetting.AppAuth.PrivateKey))
decryptedPrivateKey, err := pkcs8.ParsePKCS8PrivateKey(block.Bytes, []byte(config.BoxAppSetting.AppAuth.PassPhrase))

关于go - 替代 golang 中的 load_pem_private_key(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55522777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com