Reputation: 1
I want to make an AES 256 CBC key and iv with SHA1 digest like in openssl's EVP_BytesToKey
function, but with iOS tools. Is there an iOS alternative for that?
In openssl it looks like:
int ret = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), salt, keyingData, strlen(keyingData), 2048 /*iteration*/, resultKey, resultIV);
Later I want to use that generated key (resultKey
) and iv (resultIV
) in CommonCrypto's CCCrypt
, but I don't know how to generate them with iOS tools. Please help.
I've found a code snippet in this video, which maybe do the job, but I'm not sure. Also it's just the key, the IV is still unknown to me.
let keyByteCount = 256/8
var key = Array(repeating: 0, count: keyByteCount)
let error = SecRandomCopyBytes(kSecRandomDefault, keyByteCount, &key)
if error != errSecSuccess {
return 1
}
memset_s(&key, keyByteCount, 0, keyByteCount)
But I think this is not what I'm looking for, because it doesn't require a salt or iteration count or any algorithm (like SHA1).
Upvotes: 0
Views: 207