亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

go - 如何在go中將字符串加密為ASCII裝甲文件

go - 如何在go中將字符串加密為ASCII裝甲文件

Go
慕尼黑8549860 2022-01-10 11:00:34
我現在真的很難在我的代碼中找到錯誤——任務是將一個字符串加密到一個 pgp ASCII 裝甲文件中——這是一件簡單的事情。受此要點啟發,我使用以下函數:// pgp encryption using the pgp RSA certificate// massive thx to https://gist.github.com/jyap808/8250124func encToFile(secretString string, filename string) (string, error) {  log.Println("Public Keyring: ", publicKeyring)  encryptionType := "PGP MESSAGE"  // Read in public key  keyringFileBuffer, _ := os.Open(publicKeyring)  defer keyringFileBuffer.Close()   entityList, err := openpgp.ReadArmoredKeyRing(keyringFileBuffer)   check(err)  encbuf := bytes.NewBuffer(nil)  w, err := armor.Encode(encbuf, encryptionType, nil) // the encoder somehow makes this into ASCII armor  check(err)  plaintext, err := openpgp.Encrypt(w, entityList, nil, nil, nil)  check(err)  message := []byte(secretString)  _, err = plaintext.Write(message)  plaintext.Close()  w.Close()  // Output encrypted/encoded string  log.Println("Writing Encrypted Secred to: ", filename)  // we write the file into a file  err = ioutil.WriteFile(filename, encbuf.Bytes(), 0644)  check(err)  log.Println("File:\n", encbuf.String())  return encbuf.String(), nil}但是,另一端的人收到此錯誤消息:gpg: encrypted with RSA key, ID 5BE299DCgpg: decryption failed: No secret key非常歡迎提示和建議!
查看完整描述

1 回答

?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

但是,另一端的人收到此錯誤消息:

gpg: encrypted with RSA key, ID 5BE299DC
gpg: decryption failed: No secret key

如果您為正確的密鑰加密,我認為您沒有做錯任何事情。查看密鑰服務器上的該密鑰,您已加密為最新的(也是唯一的)加密子密鑰。

如果“另一端的人”收到一條錯誤消息,表明他不會持有密鑰,那么要么

  • 您使用錯誤的密鑰進行加密,

  • “另一個人”給了你錯誤的鑰匙或

  • “另一個人”把自己搞砸了。

您可以通過將加密的內容傳遞給gpg --list-packetsor來驗證出了什么問題pgpdump,它列出了消息中包含的 OpenPGP 數據包,并且對于調試 OpenPGP 問題非常有幫助。


查看完整回答
反對 回復 2022-01-10
  • 1 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號