Add sha1 pbkdf2 on Android

This commit is contained in:
Hugo Pointcheval 2020-04-29 22:50:42 +02:00
parent ee9490d3a4
commit 4f5b6bf351
3 changed files with 11 additions and 7 deletions

View File

@ -49,8 +49,9 @@ public class NativeCryptoPlugin : FlutterPlugin, MethodCallHandler {
val salt = call.argument<String>("salt")
val keyLength = call.argument<Int>("keyLength")
val iteration = call.argument<Int>("iteration")
val algorithm = call.argument<String>("algorithm")
val key = pbkdf2(password!!, salt!!, keyLength!!, iteration!!)
val key = pbkdf2(password!!, salt!!, keyLength!!, iteration!!, algorithm!!)
if (key.isNotEmpty()) {
result.success(key)
@ -109,13 +110,16 @@ public class NativeCryptoPlugin : FlutterPlugin, MethodCallHandler {
return md.digest(obj)
}
private fun pbkdf2(password : String, salt : String, keyLength : Int, iteration : Int) : ByteArray {
private fun pbkdf2(password : String, salt : String, keyLength : Int, iteration : Int, algorithm : String) : ByteArray {
val chars: CharArray = password.toCharArray()
val spec = PBEKeySpec(chars, salt.toByteArray(), iteration, keyLength * 8)
val skf: SecretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256")
val skf: SecretKeyFactory = if (algorithm == "sha1") {
SecretKeyFactory.getInstance("PBKDF2withHmacSHA1")
} else {
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256")
}
return skf.generateSecret(spec).encoded
}
private fun symKeygen(keySize : Int): ByteArray {

View File

@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

View File

@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
#Wed Apr 29 22:33:58 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip