Add pbkdf2 sha1 and keypair gen on iOS
This commit is contained in:
parent
0656a06eab
commit
5e30e36550
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
@ -7,6 +7,7 @@
|
||||
import Flutter
|
||||
import UIKit
|
||||
import CommonCrypto
|
||||
import Security
|
||||
|
||||
extension FlutterStandardTypedData {
|
||||
var uint8Array: Array<UInt8> {
|
||||
@ -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!))
|
||||
|
Loading…
x
Reference in New Issue
Block a user