我想在CryptoSwift庫中使用Swift中的aes-128-ctr,但是由此產生的密文太長。Swift - AES 128 ctr,密文太長
我的IV是16字節,salt 32字節,而且aes明文也是32字節,爲什麼產生的密文是48字節,因此用另外的16字節填充?
let salt: [UInt8] = Array("tkmlidnonknkqgvapjrpdcductebsozn".utf8)
let derivedKey = try PKCS5.PBKDF2(password: password, salt: salt, iterations: numberOfIterations, variant: .sha256).calculate()
let iv: [UInt8] = Array("abcdefgthksdfghj".utf8)
let aesKey: [UInt8] = Array(derivedKey[..<16])
let aes = try AES(key: aesKey, blockMode: .CTR(iv: iv))
let ciphertext = try aes.encrypt(password)
這裏的密碼是提到的32字節的明文。
此外,有沒有什麼辦法可以產生隨機鹽?我發現
let iv: [UInt8] = AES.randomIV(AES.blockSize)
生成一個隨機IV,但是我怎麼得到這樣的鹽?
它是最好避免使用CryptoSwift,其他的事情比基於Common Crypto的實現慢500到1000倍。 Apple的Common Crypto已通過FIPS認證,並且經過充分審查,使用CryptoSwift正在考慮正確性和安全性。 – zaph