Add KeyDerivation implementation in swift
This commit is contained in:
parent
a5d3b76b01
commit
1e360f16fe
25
ios/Classes/KeyGeneration.swift
Normal file
25
ios/Classes/KeyGeneration.swift
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// KeyGeneration.swift
|
||||
//
|
||||
// NativeCryptoPlugin
|
||||
//
|
||||
// Copyright (c) 2020
|
||||
// Author: Hugo Pointcheval
|
||||
//
|
||||
import Foundation
|
||||
|
||||
class KeyGeneration {
|
||||
func keygen(size : NSNumber) -> Data? {
|
||||
var bytes = [Int8](repeating: 0, count: size.intValue / 8)
|
||||
let status = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes)
|
||||
|
||||
if status == errSecSuccess {
|
||||
let keyBytes = bytes.withUnsafeBytes {
|
||||
return Data(Array($0))
|
||||
|
||||
}
|
||||
return keyBytes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user