我正在使用JOSESwift。当我使用Encrypter方法时,它返回nil,没有任何错误的细节。下面是我的代码示例。谁能帮帮忙,为什么Encrypter方法返回nil?
意图:我正在尝试为我的JWE对象设置包装密钥,从JOSESwift我可以理解Encrypter接受该cek密钥。
// Jose implementation.
let joseHeader = JWEHeader(algorithm: .direct,
encryptionAlgorithm: .A128CBCHS256)
let joseEncrypter = Encrypter(keyEncryptionAlgorithm: .RSAOAEP,
encryptionKey: cekKeyData,
contentEncyptionAlgorithm: .A128CBCHS256)!
let josePayload = Payload(Data(base64Encoded: jsonString)!)
let joseJWE = try? JWE(header: joseHeader, payload: josePayload, encrypter: joseEncrypter)发布于 2020-01-25 01:47:22
我怀疑您传递了错误类型的密钥,或者错误地选择了.RSAOAEP作为您的算法并表示为.direct。
/// - key: The key used to perform the encryption. If the `keyEncryptionAlgorithm` is `.direct`, the
/// `encryptionKey` is the shared symmetric content encryption key. Otherwise the `encryptionKey` is the
/// public key of the receiver. See [RFC-7516](https://tools.ietf.org/html/rfc7516#section-5.1) for
/// details.在给定传入参数的情况下,仅在以下情况下从that code返回nil:
switch (keyEncryptionAlgorithm, contentEncyptionAlgorithm) {
case (.RSA1_5, .A256CBCHS512), (.RSAOAEP, .A256CBCHS512), (.RSAOAEP256, .A256CBCHS512), (.RSA1_5, .A128CBCHS256), (.RSAOAEP, .A128CBCHS256), (.RSAOAEP256, .A128CBCHS256):
guard type(of: key) is RSAEncrypter.KeyType.Type else {
return nil
}
// ...这表明cekKeyData不是RSAEncrypter.KeyType类型。我怀疑它是一个生成的AES密钥。
https://stackoverflow.com/questions/59898973
复制相似问题