|
1
|
import Foundation |
|
2
|
|
|
3
|
func secRandom(count: Int) -> Data? { |
|
4
|
var bytes = [Int8](repeating: 0, count: count) |
|
5
|
let status = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes) |
|
6
|
|
|
7
|
if status == errSecSuccess { |
|
8
|
return Data(bytes: bytes, count: bytes.count) |
|
9
|
} |
|
10
|
|
|
11
|
return nil |
|
12
|
} |