我現(xiàn)在真的很難在我的代碼中找到錯(cuò)誤——任務(wù)是將一個(gè)字符串加密到一個(gè) pgp ASCII 裝甲文件中——這是一件簡(jiǎn)單的事情。受此要點(diǎn)啟發(fā),我使用以下函數(shù):// 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}但是,另一端的人收到此錯(cuò)誤消息:gpg: encrypted with RSA key, ID 5BE299DCgpg: decryption failed: No secret key非常歡迎提示和建議!
go - 如何在go中將字符串加密為ASCII裝甲文件
慕尼黑8549860
2022-01-10 11:00:34