@onekeyfe/react-native-pbkdf2 1.1.55 → 1.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Pbkdf2_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Pbkdf2_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.pbkdf2"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lintOptions {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.pbkdf2
|
|
2
|
+
|
|
3
|
+
import android.util.Base64
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
7
|
+
import javax.crypto.SecretKeyFactory
|
|
8
|
+
import javax.crypto.spec.PBEKeySpec
|
|
9
|
+
|
|
10
|
+
@ReactModule(name = Pbkdf2Module.NAME)
|
|
11
|
+
class Pbkdf2Module(reactContext: ReactApplicationContext) :
|
|
12
|
+
NativePbkdf2Spec(reactContext) {
|
|
13
|
+
|
|
14
|
+
companion object {
|
|
15
|
+
const val NAME = "Pbkdf2"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override fun getName(): String = NAME
|
|
19
|
+
|
|
20
|
+
override fun derive(
|
|
21
|
+
password: String,
|
|
22
|
+
salt: String,
|
|
23
|
+
rounds: Double,
|
|
24
|
+
keyLength: Double,
|
|
25
|
+
hash: String,
|
|
26
|
+
promise: Promise
|
|
27
|
+
) {
|
|
28
|
+
Thread {
|
|
29
|
+
try {
|
|
30
|
+
val passwordBytes = Base64.decode(password, Base64.DEFAULT)
|
|
31
|
+
val saltBytes = Base64.decode(salt, Base64.DEFAULT)
|
|
32
|
+
val iterationCount = rounds.toInt()
|
|
33
|
+
val keyLengthBits = keyLength.toInt() * 8
|
|
34
|
+
|
|
35
|
+
val algorithm = when (hash.uppercase()) {
|
|
36
|
+
"SHA256", "SHA-256" -> "PBKDF2WithHmacSHA256"
|
|
37
|
+
"SHA512", "SHA-512" -> "PBKDF2WithHmacSHA512"
|
|
38
|
+
else -> "PBKDF2WithHmacSHA256"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
val spec = PBEKeySpec(
|
|
42
|
+
String(passwordBytes, Charsets.UTF_8).toCharArray(),
|
|
43
|
+
saltBytes,
|
|
44
|
+
iterationCount,
|
|
45
|
+
keyLengthBits
|
|
46
|
+
)
|
|
47
|
+
val factory = SecretKeyFactory.getInstance(algorithm)
|
|
48
|
+
val derivedKey = factory.generateSecret(spec).encoded
|
|
49
|
+
promise.resolve(Base64.encodeToString(derivedKey, Base64.NO_WRAP))
|
|
50
|
+
} catch (e: Exception) {
|
|
51
|
+
promise.reject("PBKDF2_ERROR", e.message, e)
|
|
52
|
+
}
|
|
53
|
+
}.start()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.pbkdf2
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
9
|
+
|
|
10
|
+
class Pbkdf2Package : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == Pbkdf2Module.NAME) {
|
|
13
|
+
Pbkdf2Module(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
20
|
+
return ReactModuleInfoProvider {
|
|
21
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
22
|
+
moduleInfos[Pbkdf2Module.NAME] = ReactModuleInfo(
|
|
23
|
+
Pbkdf2Module.NAME,
|
|
24
|
+
Pbkdf2Module.NAME,
|
|
25
|
+
false, // canOverrideExistingModule
|
|
26
|
+
false, // needsEagerInit
|
|
27
|
+
false, // isCxxModule
|
|
28
|
+
true // isTurboModule
|
|
29
|
+
)
|
|
30
|
+
moduleInfos
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-pbkdf2",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.56",
|
|
4
4
|
"description": "react-native-pbkdf2",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"!**/__tests__",
|
|
22
22
|
"!**/__fixtures__",
|
|
23
23
|
"!**/__mocks__",
|
|
24
|
-
"!**/.*"
|
|
24
|
+
"!**/.*",
|
|
25
|
+
"android"
|
|
25
26
|
],
|
|
26
27
|
"scripts": {
|
|
27
28
|
"clean": "del-cli ios/build lib",
|