【发布时间】:2021-10-28 05:46:34
【问题描述】:
我正在尝试在 Ubuntu 上使用 bash 创建/更新 GitHub 机密。
他们的 api 文档说我应该
- 从 repo 中获取公钥
- 用它加密秘密
- 创建/更新 GitHub 密码
但示例仅在 NodeJS 和 Python 中,我不确定如何使用 Ubuntu 上的 bash 中提到的 libsodium 来实现我需要的。
https://docs.github.com/en/rest/reference/actions#create-or-update-a-repository-secret
我能够使用key 和key_id 获得公众
$ curl -s \
-H "authorization: Bearer $MY_ACCESS_TOKEN" \
https://api.github.com/repos/MYORG/MYREPO/actions/secrets/public-key
{
"key_id": "123456789012345678",
"key": "abcdHXZ2BrPAFPrZHy1AAct3B12k7BPgxXgdtxcABCo="
}
我能够使用 Python 3 示例生成似乎是我的秘密的有效加密值:
#!/usr/bin/python3
from base64 import b64encode
from nacl import encoding, public
def encrypt(public_key: str, secret_value: str) -> str:
public_key = public.PublicKey(public_key.encode("utf-8"), encoding.Base64Encoder())
sealed_box = public.SealedBox(public_key)
encrypted = sealed_box.encrypt(secret_value.encode("utf-8"))
return b64encode(encrypted).decode("utf-8")
print(encrypt("abcdHXZ2BrPAFPrZHy1AAct3B12k7BPgxXgdtxcABCo=", "ABCDEF1234"))
$ ./encrypt-secret.py
ST5Blke5GXO2FyMLUbYAhkmzLKJ3cljd1lI97q028gcrq3XC9aTqPlNzbMQAI5iHoj/70ao0/GOrhg==
但我正在寻找一个 bash 实现。
【问题讨论】:
标签: bash github encryption command-line-interface libsodium