登录
首页 >  Golang >  Go问答

SecKeyCreateEncryptedData调用时所需的辅助参数是什么?

来源:stackoverflow

时间:2024-02-28 11:39:24 260浏览 收藏

从现在开始,我们要努力学习啦!今天我给大家带来《SecKeyCreateEncryptedData调用时所需的辅助参数是什么?》,感兴趣的朋友请继续看下去吧!下文中的内容我们主要会涉及到等等知识点,如果在阅读本文过程中有遇到不清楚的地方,欢迎留言呀!我们一起讨论,一起学习!

问题内容

我正在使用 rsaencryptionoaepsha256aesgcm 在 ios 上使用 seckeycreateencrypteddata 加密一些数据,然后在 golang 后端解密相同的数据。我使用 3072 位 rsa 公钥来加密对称密钥。当我从 ios 获取数据到后端时,我成功解密对称密钥,但 gcm 标签验证失败。我使用与 ios 相同的 16 字节 iv,但不知道 ios 在加密时是否使用任何 aad(附加身份验证数据)。有谁知道适用于 ios 的 rsaencryptionoaepsha256aesgcm 是否使用某些 aad?这是适用于 ios 10+ 的。

我已经尝试过使用 nil、空 16 字节数组、aes 键本身、nonce 作为 aad,但这些都不起作用。

在斯威夫特:

private let algorithm = seckeyalgorithm.rsaencryptionoaepsha256aesgcm
// key is 3072 bit rsa public key
// api doesnt take any aad
seckeycreateencrypteddata(key, algorithm, cfdata, &error)

在 go 语言中:

c, err := aes.NewCipher(aesKey)
gcm, err := cipher.NewGCMWithNonceSize(c, 16)
nonce := make([]byte, 16)
// Data has both the ciphertext and the gcm tag as the last 16 bytes
// Last field in the api is the aad
dec, err := gcm.Open(nil, nonce, data, nil)

这是我在 golang 中看到的错误 “cipher:消息身份验证失败”,并且从验证 gcm 标记的代码中抛出错误。


解决方案


找到了。 AAD 是 ASN.1 DER 格式的 RSA 公钥。

理论要掌握,实操不能落!以上关于《SecKeyCreateEncryptedData调用时所需的辅助参数是什么?》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>