SecRandomCopyBytes and SymmetricKey

40 Views Asked by At

Can SymmetricKey be used as substitute for SecRandomCopyBytes? I found this code snippet in WWDC19 video

var key = Array(repeating: 0, count: 32)
let err = SecRandomCopyBytes(kSecRandomDefault, keyByteCount, &key)
memset_s(&key, 32, 0, 32)

and then use this as substitute:

let key = SymmetricKey(size: .bits256)

Documentation for SymetricKey is quite lean. So I am not sure is it safe to use SymmetricKey as CPRNG? If yes, why? Thank you!

0

There are 0 best solutions below