From 1e360f16fea69156ea9df3e314530f8e2fb15b2f Mon Sep 17 00:00:00 2001 From: Pointcheval Hugo Date: Sat, 19 Dec 2020 21:44:31 +0100 Subject: [PATCH] Add KeyDerivation implementation in swift --- ios/Classes/KeyGeneration.swift | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ios/Classes/KeyGeneration.swift diff --git a/ios/Classes/KeyGeneration.swift b/ios/Classes/KeyGeneration.swift new file mode 100644 index 0000000..a918f9b --- /dev/null +++ b/ios/Classes/KeyGeneration.swift @@ -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 + } +}