From 46b1a5248c90156ca285dc1195fc65cd504396ef Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Wed, 29 Apr 2020 23:04:20 +0200 Subject: [PATCH] Add sha512 on pbkdf2 Sift --- ios/Classes/SwiftNativeCryptoPlugin.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ios/Classes/SwiftNativeCryptoPlugin.swift b/ios/Classes/SwiftNativeCryptoPlugin.swift index 6c46a80..9b9a6be 100644 --- a/ios/Classes/SwiftNativeCryptoPlugin.swift +++ b/ios/Classes/SwiftNativeCryptoPlugin.swift @@ -82,6 +82,10 @@ func pbkdf2(hash: CCPBKDFAlgorithm, password: String, salt: String, keyByteCount return derivedKeyData } +func pbkdf2sha512(password: String, salt: String, keyByteCount: Int, rounds: Int) -> Data? { + return pbkdf2(hash: CCPBKDFAlgorithm(kCCPRFHmacAlgSHA512), password: password, salt: salt, keyByteCount: keyByteCount, rounds: rounds) +} + func pbkdf2sha256(password: String, salt: String, keyByteCount: Int, rounds: Int) -> Data? { return pbkdf2(hash: CCPBKDFAlgorithm(kCCPRFHmacAlgSHA256), password: password, salt: salt, keyByteCount: keyByteCount, rounds: rounds) } @@ -174,8 +178,10 @@ public class SwiftNativeCryptoPlugin: NSObject, FlutterPlugin { if (algo == "sha1") { keyBytes = pbkdf2sha1(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) - } else { + } else if (algo == "sha256"){ keyBytes = pbkdf2sha256(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) + } else if (algo == "sha512"){ + keyBytes = pbkdf2sha512(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) } if keyBytes != nil {