Add sha1 pbkdf2 on Android
This commit is contained in:
parent
ee9490d3a4
commit
4f5b6bf351
@ -49,8 +49,9 @@ public class NativeCryptoPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
val salt = call.argument<String>("salt")
|
val salt = call.argument<String>("salt")
|
||||||
val keyLength = call.argument<Int>("keyLength")
|
val keyLength = call.argument<Int>("keyLength")
|
||||||
val iteration = call.argument<Int>("iteration")
|
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()) {
|
if (key.isNotEmpty()) {
|
||||||
result.success(key)
|
result.success(key)
|
||||||
@ -109,13 +110,16 @@ public class NativeCryptoPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
return md.digest(obj)
|
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 chars: CharArray = password.toCharArray()
|
||||||
|
|
||||||
val spec = PBEKeySpec(chars, salt.toByteArray(), iteration, keyLength * 8)
|
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
|
return skf.generateSecret(spec).encoded
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun symKeygen(keySize : Int): ByteArray {
|
private fun symKeygen(keySize : Int): ByteArray {
|
||||||
|
@ -6,7 +6,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#Fri Jun 23 08:50:38 CEST 2017
|
#Wed Apr 29 22:33:58 CEST 2020
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user