【问题标题】:What is the additional authenticated data used by swift api SecKeyCreateEncryptedData?swift api SecKeyCreateEncryptedData 使用的额外认证数据是什么?
【发布时间】:2019-09-12 05:31:44
【问题描述】:

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

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

在 Swift 中:

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: message authentication failed" 并且从验证 gcm 标签的代码中抛出错误。

【问题讨论】:

    标签: ios swift go encryption aes-gcm


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 2015-03-08
      相关资源
      最近更新 更多