【发布时间】:2016-05-06 14:56:15
【问题描述】:
我现在真的很难在我的代码中找到错误 - 任务是将字符串加密到一个 pgp ASCII 装甲文件中 - 一件简单的事情可以想到。
受gist的启发,我使用了以下函数:
// pgp encryption using the pgp RSA certificate
// massive thx to https://gist.github.com/jyap808/8250124
func 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 5BE299DC
gpg: decryption failed: No secret key
非常欢迎提示和建议!
【问题讨论】:
-
如果您为正确的密钥加密,我认为您没有做错任何事情。查看密钥服务器上的该密钥,您已加密为最新的(也是唯一的)加密子密钥。如果“另一端的人”收到错误消息,他没有持有密钥,那么要么你使用了错误的密钥进行加密,要么对方给了你错误的密钥,要么对方搞砸了自己。
-
我使用他们在他们的网站上发布的 ASCII 装甲密钥。我认为关键是正确的。但是,当我们使用脚本时,他们会尝试在命令行上使用 gpg 解密。
-
没关系。 “其他人”实现正确地意识到您为(子)密钥
5BE299DC加密,但没有此密钥。只有我的评论中列出的原因之一会导致此消息。 -
嗨 Jens,我们现在尝试使用我的联系人的个人密钥,它确实像一个魅力。看起来加密不仅对像我这样的网络人来说是困难的;) - 如果您将评论添加为答案,我很乐意将其标记为最后一个。