解碼 GPG 金鑰
可以使用各種方法來完成 Base64 編碼 GPG 金鑰的解碼。 其中一種常見的方法是從檔案解碼。
從檔案解碼
若要從檔案解碼 GPG 金鑰,請遵循下列步驟:
- 將已編碼的金鑰複製到檔案: 建立名為
key.txt的檔案,並將 Base64 編碼的 GPG 金鑰貼入其中。 根據系統上安裝的編碼器,複製必要的程式碼 Snippet:
base64:
如果您已在系統中安裝 base64,請使用 key.txt 檔中的下列程式碼 Snippet:
# Define file paths
encoded_key_file="key.txt"
decoded_key_file="decoded_key.txt"
# Read the content of the file
encoded_key=$(<"$encoded_key_file")
# Decode the key using base64 command
decoded_key=$(echo "$encoded_key" | base64 -d)
# Save the decoded key to a file
echo $decoded_key > "$decoded_key_file"
# Import the decoded key into GPG
gpg --import "$decoded_key_file"
如果您已在系統上安裝 OpenSSL:
如果您已在系統中安裝 OpenSSL,請使用 key.txt 檔案中的下列程式碼 Snippet:
encoded_key_file="key.txt"
decoded_key_file="decoded_key.txt"
# Read the content of the file
encoded_key=$(<"$encoded_key_file")
# Decode the key using openssl command
decoded_key=$(echo "$encoded_key" | openssl base64 -d)
# Save the decoded key to a file
echo $decoded_key > "$decoded_key_file"
# Import the decoded key into GPG
gpg --import "$decoded_key_file"
- 執行後,您會發現金鑰已成功匯入 GPG 金鑰圈。