diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/Classes/SwiftNativeCryptoPlugin.swift b/ios/Classes/SwiftNativeCryptoPlugin.swift index 07043a7..6c46a80 100644 --- a/ios/Classes/SwiftNativeCryptoPlugin.swift +++ b/ios/Classes/SwiftNativeCryptoPlugin.swift @@ -7,6 +7,7 @@ import Flutter import UIKit import CommonCrypto +import Security extension FlutterStandardTypedData { var uint8Array: Array { @@ -19,6 +20,17 @@ extension FlutterStandardTypedData { } } +@available(iOS 10.0, *) +func generateKeypair() { + var publicKeySec, privateKeySec: SecKey? + let keyattribute = [ + kSecAttrKeyType as String: kSecAttrKeyTypeECSECPrimeRandom, + kSecAttrKeySizeInBits as String : 256 + ] as CFDictionary + SecKeyGeneratePair(keyattribute, &publicKeySec, &privateKeySec) + +} + func crypt(operation: Int, algorithm: Int, options: Int, key: Data, initializationVector: Data, dataIn: Data) -> Data? { return key.withUnsafeBytes { keyUnsafeRawBufferPointer in @@ -74,6 +86,11 @@ func pbkdf2sha256(password: String, salt: String, keyByteCount: Int, rounds: Int return pbkdf2(hash: CCPBKDFAlgorithm(kCCPRFHmacAlgSHA256), password: password, salt: salt, keyByteCount: keyByteCount, rounds: rounds) } +func pbkdf2sha1(password: String, salt: String, keyByteCount: Int, rounds: Int) -> Data? { + return pbkdf2(hash: CCPBKDFAlgorithm(kCCPRFHmacAlgSHA1), password: password, salt: salt, keyByteCount: keyByteCount, rounds: rounds) +} + + func randomGenerateBytes(count: Int) -> Data? { let bytes = UnsafeMutableRawPointer.allocate(byteCount: count, alignment: 1) defer { bytes.deallocate() } @@ -151,8 +168,15 @@ public class SwiftNativeCryptoPlugin: NSObject, FlutterPlugin { let salt = args["salt"] as! String let keyLength = args["keyLength"] as! NSNumber let iteration = args["iteration"] as! NSNumber + let algo = args["algorithm"] as! String - let keyBytes = pbkdf2sha256(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) + var keyBytes: Data? + + if (algo == "sha1") { + keyBytes = pbkdf2sha1(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) + } else { + keyBytes = pbkdf2sha256(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) + } if keyBytes != nil { result(FlutterStandardTypedData.init(bytes: keyBytes!))