[英]CryptoSwift with Xcode 9 and AES Decryption
I am using Xcode 9.0 and CryptoSwift (0.7.2). 我正在使用Xcode 9.0和CryptoSwift(0.7.2)。 I am trying to extend String to decrypt an AES128 encrypted string.
我正在尝试扩展String以解密AES128加密字符串。 I've added CryptoSwift successfully with Pods but I get the following compilation error - what am I doing wrong?
我已经使用Pod成功添加了CryptoSwift,但是我收到了以下编译错误 - 我做错了什么?
'PKCS7' cannot be constructed because it has no accessible initializers 无法构造'PKCS7',因为它没有可访问的初始值设定项
Here is the extension: 这是扩展名:
import Foundation
import CryptoSwift
extension String {
// https://stackoverflow.com/questions/27072021/aes-encrypt-and-decrypt
func aesDecrypt(key: String, iv: String) throws -> String {
let data = Data(base64Encoded: self)!
let decrypted = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()).decrypt([UInt8](data))
let decryptedData = Data(decrypted)
return String(bytes: decryptedData.bytes, encoding: .utf8) ?? "Could not decrypt"
}
}
I've checked out CryptoSwift
's documentation, and I found a sample code: 我查看了
CryptoSwift
的文档,我找到了一个示例代码:
let decrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).decrypt(encrypted)
and I think it uses .pkcs7
, instead of PKCS7()
. 我认为它使用
.pkcs7
而不是PKCS7()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.