@functionland/react-native-fula 1.55.12 → 1.55.16
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.
- package/LICENSE +20 -20
- package/android/build.gradle +114 -114
- package/android/gradle.properties +8 -8
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/AndroidManifestNew.xml +2 -2
- package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
- package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
- package/android/src/main/java/land/fx/fula/FulaModule.java +2057 -1991
- package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
- package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
- package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
- package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
- package/ios/Cryptography.swift +59 -59
- package/ios/Fula-Bridging-Header.h +3 -3
- package/ios/Fula.mm +272 -262
- package/ios/Fula.swift +2284 -2207
- package/ios/Fula.xcodeproj/project.pbxproj +2 -2
- package/ios/UserDataHelper.swift +143 -143
- package/lib/commonjs/index.js +1 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-consts.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-events.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-query.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-tx.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api.js.map +1 -1
- package/lib/commonjs/interfaces/augment-types.js.map +1 -1
- package/lib/commonjs/interfaces/definitions.js.map +1 -1
- package/lib/commonjs/interfaces/defintions.js.map +1 -1
- package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/commonjs/interfaces/index.js.map +1 -1
- package/lib/commonjs/interfaces/lookup.js +300 -300
- package/lib/commonjs/interfaces/lookup.js.map +1 -1
- package/lib/commonjs/interfaces/registry.js.map +1 -1
- package/lib/commonjs/interfaces/types-lookup.js.map +1 -1
- package/lib/commonjs/interfaces/types.js.map +1 -1
- package/lib/commonjs/protocols/blockchain.js +133 -67
- package/lib/commonjs/protocols/blockchain.js.map +1 -1
- package/lib/commonjs/protocols/chain-api.js.map +1 -1
- package/lib/commonjs/protocols/fula.js.map +1 -1
- package/lib/commonjs/protocols/fx-ai.js.map +1 -1
- package/lib/commonjs/protocols/fxblox.js +3 -3
- package/lib/commonjs/protocols/fxblox.js.map +1 -1
- package/lib/commonjs/types/blockchain.js.map +1 -1
- package/lib/commonjs/types/fxblox.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/interfaces/augment-api-consts.js.map +1 -1
- package/lib/module/interfaces/augment-api-errors.js.map +1 -1
- package/lib/module/interfaces/augment-api-events.js.map +1 -1
- package/lib/module/interfaces/augment-api-query.js.map +1 -1
- package/lib/module/interfaces/augment-api-rpc.js.map +1 -1
- package/lib/module/interfaces/augment-api-runtime.js.map +1 -1
- package/lib/module/interfaces/augment-api-tx.js.map +1 -1
- package/lib/module/interfaces/augment-api.js.map +1 -1
- package/lib/module/interfaces/augment-types.js.map +1 -1
- package/lib/module/interfaces/definitions.js.map +1 -1
- package/lib/module/interfaces/defintions.js.map +1 -1
- package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/module/interfaces/index.js.map +1 -1
- package/lib/module/interfaces/lookup.js +300 -300
- package/lib/module/interfaces/lookup.js.map +1 -1
- package/lib/module/interfaces/registry.js.map +1 -1
- package/lib/module/interfaces/types-lookup.js.map +1 -1
- package/lib/module/interfaces/types.js.map +1 -1
- package/lib/module/protocols/blockchain.js +130 -66
- package/lib/module/protocols/blockchain.js.map +1 -1
- package/lib/module/protocols/chain-api.js.map +1 -1
- package/lib/module/protocols/fula.js.map +1 -1
- package/lib/module/protocols/fx-ai.js.map +1 -1
- package/lib/module/protocols/fxblox.js +3 -3
- package/lib/module/protocols/fxblox.js.map +1 -1
- package/lib/module/types/blockchain.js.map +1 -1
- package/lib/module/types/fxblox.js.map +1 -1
- package/package.json +177 -176
- package/react-native-fula.podspec +47 -47
- package/src/index.tsx +4 -4
- package/src/interfaces/augment-api-consts.ts +273 -273
- package/src/interfaces/augment-api-errors.ts +474 -474
- package/src/interfaces/augment-api-events.ts +448 -448
- package/src/interfaces/augment-api-query.ts +466 -466
- package/src/interfaces/augment-api-rpc.ts +617 -617
- package/src/interfaces/augment-api-runtime.ts +223 -223
- package/src/interfaces/augment-api-tx.ts +709 -709
- package/src/interfaces/augment-api.ts +9 -9
- package/src/interfaces/augment-types.ts +1322 -1322
- package/src/interfaces/definitions.ts +1 -1
- package/src/interfaces/defintions.ts +1 -1
- package/src/interfaces/fulaNativeModule.ts +177 -175
- package/src/interfaces/index.ts +3 -3
- package/src/interfaces/lookup.ts +2011 -2011
- package/src/interfaces/registry.ts +163 -163
- package/src/interfaces/types-lookup.ts +2165 -2165
- package/src/interfaces/types.ts +2 -2
- package/src/protocols/blockchain.ts +716 -644
- package/src/protocols/fxblox.ts +442 -442
package/LICENSE
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Ehsan Shariati <ehsan6sha@gmail.com> (https://github.com/ehsan6sha)
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
in the Software without restriction, including without limitation the rights
|
|
7
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
furnished to do so, subject to the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ehsan Shariati <ehsan6sha@gmail.com> (https://github.com/ehsan6sha)
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/android/build.gradle
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import com.android.Version
|
|
2
|
-
|
|
3
|
-
buildscript {
|
|
4
|
-
repositories {
|
|
5
|
-
google()
|
|
6
|
-
mavenCentral()
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
dependencies {
|
|
10
|
-
classpath "com.android.tools.build:gradle:8.
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
def isNewArchitectureEnabled() {
|
|
15
|
-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
apply plugin: "com.android.library"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
22
|
-
|
|
23
|
-
if (isNewArchitectureEnabled()) {
|
|
24
|
-
apply plugin: "com.facebook.react"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
def getExtOrDefault(name) {
|
|
28
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Fula_" + name]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
def getExtOrIntegerDefault(name) {
|
|
32
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Fula_" + name]).toInteger()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static def supportsNamespace() {
|
|
36
|
-
def parsed = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
37
|
-
def major = parsed[0].toInteger()
|
|
38
|
-
def minor = parsed[1].toInteger()
|
|
39
|
-
|
|
40
|
-
// Namespace support was added in 7.3.0
|
|
41
|
-
if (major == 7 && minor >= 3) {
|
|
42
|
-
return true
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return major >= 8
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
android {
|
|
49
|
-
if (supportsNamespace()) {
|
|
50
|
-
namespace "land.fx.fula"
|
|
51
|
-
|
|
52
|
-
sourceSets {
|
|
53
|
-
main {
|
|
54
|
-
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
60
|
-
|
|
61
|
-
defaultConfig {
|
|
62
|
-
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
63
|
-
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
64
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
65
|
-
}
|
|
66
|
-
buildTypes {
|
|
67
|
-
release {
|
|
68
|
-
minifyEnabled false
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
lintOptions {
|
|
73
|
-
disable "GradleCompatible"
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
compileOptions {
|
|
77
|
-
sourceCompatibility JavaVersion.VERSION_17
|
|
78
|
-
targetCompatibility JavaVersion.VERSION_17
|
|
79
|
-
}
|
|
80
|
-
ndkVersion '26.2.11394342'
|
|
81
|
-
buildFeatures {
|
|
82
|
-
buildConfig true
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
repositories {
|
|
87
|
-
mavenLocal()
|
|
88
|
-
google()
|
|
89
|
-
mavenCentral()
|
|
90
|
-
|
|
91
|
-
// Add this repo to get go-fula package
|
|
92
|
-
maven { url 'https://jitpack.io' }
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
dependencies {
|
|
97
|
-
// For < 0.71, this will be from the local maven repo
|
|
98
|
-
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
99
|
-
//noinspection GradleDynamicVersion
|
|
100
|
-
implementation "com.facebook.react:react-android:+"
|
|
101
|
-
implementation 'com.github.functionland:fula-build-aar:v1.55.
|
|
102
|
-
implementation 'com.github.functionland:wnfs-android:v1.8.2' // From jitpack.io
|
|
103
|
-
implementation 'commons-io:commons-io:20030203.000550'
|
|
104
|
-
implementation 'commons-codec:commons-codec:1.16.0'
|
|
105
|
-
// implementation files('mobile.aar')
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (isNewArchitectureEnabled()) {
|
|
109
|
-
react {
|
|
110
|
-
jsRootDir = file("../src/")
|
|
111
|
-
libraryName = "Fula"
|
|
112
|
-
codegenJavaPackageName = "land.fx.fula"
|
|
113
|
-
}
|
|
114
|
-
}
|
|
1
|
+
import com.android.Version
|
|
2
|
+
|
|
3
|
+
buildscript {
|
|
4
|
+
repositories {
|
|
5
|
+
google()
|
|
6
|
+
mavenCentral()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
dependencies {
|
|
10
|
+
classpath "com.android.tools.build:gradle:8.7.3"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def isNewArchitectureEnabled() {
|
|
15
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: "com.android.library"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
22
|
+
|
|
23
|
+
if (isNewArchitectureEnabled()) {
|
|
24
|
+
apply plugin: "com.facebook.react"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def getExtOrDefault(name) {
|
|
28
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Fula_" + name]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def getExtOrIntegerDefault(name) {
|
|
32
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Fula_" + name]).toInteger()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static def supportsNamespace() {
|
|
36
|
+
def parsed = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
37
|
+
def major = parsed[0].toInteger()
|
|
38
|
+
def minor = parsed[1].toInteger()
|
|
39
|
+
|
|
40
|
+
// Namespace support was added in 7.3.0
|
|
41
|
+
if (major == 7 && minor >= 3) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return major >= 8
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
android {
|
|
49
|
+
if (supportsNamespace()) {
|
|
50
|
+
namespace "land.fx.fula"
|
|
51
|
+
|
|
52
|
+
sourceSets {
|
|
53
|
+
main {
|
|
54
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
60
|
+
|
|
61
|
+
defaultConfig {
|
|
62
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
63
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
64
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
65
|
+
}
|
|
66
|
+
buildTypes {
|
|
67
|
+
release {
|
|
68
|
+
minifyEnabled false
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
lintOptions {
|
|
73
|
+
disable "GradleCompatible"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
compileOptions {
|
|
77
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
78
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
79
|
+
}
|
|
80
|
+
ndkVersion '26.2.11394342'
|
|
81
|
+
buildFeatures {
|
|
82
|
+
buildConfig true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
repositories {
|
|
87
|
+
mavenLocal()
|
|
88
|
+
google()
|
|
89
|
+
mavenCentral()
|
|
90
|
+
|
|
91
|
+
// Add this repo to get go-fula package
|
|
92
|
+
maven { url 'https://jitpack.io' }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
dependencies {
|
|
97
|
+
// For < 0.71, this will be from the local maven repo
|
|
98
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
99
|
+
//noinspection GradleDynamicVersion
|
|
100
|
+
implementation "com.facebook.react:react-android:+"
|
|
101
|
+
implementation 'com.github.functionland:fula-build-aar:v1.55.15' // From jitpack.io
|
|
102
|
+
implementation 'com.github.functionland:wnfs-android:v1.8.2' // From jitpack.io
|
|
103
|
+
implementation 'commons-io:commons-io:20030203.000550'
|
|
104
|
+
implementation 'commons-codec:commons-codec:1.16.0'
|
|
105
|
+
// implementation files('mobile.aar')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (isNewArchitectureEnabled()) {
|
|
109
|
+
react {
|
|
110
|
+
jsRootDir = file("../src/")
|
|
111
|
+
libraryName = "Fula"
|
|
112
|
+
codegenJavaPackageName = "land.fx.fula"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
Fula_kotlinVersion=1.9.22
|
|
2
|
-
Fula_minSdkVersion=26
|
|
3
|
-
Fula_targetSdkVersion=
|
|
4
|
-
Fula_compileSdkVersion=
|
|
5
|
-
Fula_ndkversion=26.2.11394342
|
|
6
|
-
android.useAndroidX=true
|
|
7
|
-
android.enableJetifier=true
|
|
8
|
-
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
|
1
|
+
Fula_kotlinVersion=1.9.22
|
|
2
|
+
Fula_minSdkVersion=26
|
|
3
|
+
Fula_targetSdkVersion=35
|
|
4
|
+
Fula_compileSdkVersion=35
|
|
5
|
+
Fula_ndkversion=26.2.11394342
|
|
6
|
+
android.useAndroidX=true
|
|
7
|
+
android.enableJetifier=true
|
|
8
|
+
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
-
package="land.fx.fula">
|
|
3
|
-
</manifest>
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
package="land.fx.fula">
|
|
3
|
+
</manifest>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
-
</manifest>
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
</manifest>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
package land.fx.fula;
|
|
2
|
-
|
|
3
|
-
public final class ConfigRef {
|
|
4
|
-
public byte[] identity;
|
|
5
|
-
public java.lang.String storePath;
|
|
6
|
-
}
|
|
7
|
-
|
|
1
|
+
package land.fx.fula;
|
|
2
|
+
|
|
3
|
+
public final class ConfigRef {
|
|
4
|
+
public byte[] identity;
|
|
5
|
+
public java.lang.String storePath;
|
|
6
|
+
}
|
|
7
|
+
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
package land.fx.fula;
|
|
2
|
-
|
|
3
|
-
import android.util.Base64;
|
|
4
|
-
|
|
5
|
-
import java.io.UnsupportedEncodingException;
|
|
6
|
-
import java.nio.charset.StandardCharsets;
|
|
7
|
-
import java.security.InvalidAlgorithmParameterException;
|
|
8
|
-
import java.security.InvalidKeyException;
|
|
9
|
-
import java.security.NoSuchAlgorithmException;
|
|
10
|
-
import java.security.spec.InvalidKeySpecException;
|
|
11
|
-
import java.security.SecureRandom;
|
|
12
|
-
import java.nio.ByteBuffer;
|
|
13
|
-
import java.security.spec.InvalidParameterSpecException;
|
|
14
|
-
|
|
15
|
-
import javax.crypto.BadPaddingException;
|
|
16
|
-
import javax.crypto.Cipher;
|
|
17
|
-
import javax.crypto.IllegalBlockSizeException;
|
|
18
|
-
import javax.crypto.NoSuchPaddingException;
|
|
19
|
-
import javax.crypto.SecretKey;
|
|
20
|
-
import javax.crypto.SecretKeyFactory;
|
|
21
|
-
import javax.crypto.spec.PBEKeySpec;
|
|
22
|
-
import javax.crypto.spec.SecretKeySpec;
|
|
23
|
-
import javax.crypto.spec.GCMParameterSpec;
|
|
24
|
-
|
|
25
|
-
public class Cryptography {
|
|
26
|
-
public static String encryptMsg(String message, SecretKey secret, byte[] iv)
|
|
27
|
-
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {
|
|
28
|
-
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
|
29
|
-
if (iv == null || iv.length == 0) {
|
|
30
|
-
iv = new byte[12]; // Ensure this is randomly generated for each encryption.
|
|
31
|
-
new SecureRandom().nextBytes(iv);
|
|
32
|
-
}
|
|
33
|
-
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
|
|
34
|
-
cipher.init(Cipher.ENCRYPT_MODE, secret, spec);
|
|
35
|
-
byte[] cipherText = cipher.doFinal(message.getBytes(StandardCharsets.UTF_8));
|
|
36
|
-
ByteBuffer byteBuffer = ByteBuffer.allocate(iv.length + cipherText.length);
|
|
37
|
-
byteBuffer.put(iv);
|
|
38
|
-
byteBuffer.put(cipherText);
|
|
39
|
-
return Base64.encodeToString(byteBuffer.array(), Base64.NO_WRAP);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public static String decryptMsg(String cipherText, SecretKey secret)
|
|
43
|
-
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
|
44
|
-
ByteBuffer byteBuffer = ByteBuffer.wrap(Base64.decode(cipherText, Base64.NO_WRAP));
|
|
45
|
-
byte[] iv = new byte[12];
|
|
46
|
-
byteBuffer.get(iv);
|
|
47
|
-
byte[] cipherBytes = new byte[byteBuffer.remaining()];
|
|
48
|
-
byteBuffer.get(cipherBytes);
|
|
49
|
-
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
|
50
|
-
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
|
|
51
|
-
cipher.init(Cipher.DECRYPT_MODE, secret, spec);
|
|
52
|
-
String decryptString = new String(cipher.doFinal(cipherBytes), StandardCharsets.UTF_8);
|
|
53
|
-
return decryptString;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public static SecretKey generateKey(byte[] key)
|
|
57
|
-
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
|
58
|
-
PBEKeySpec pbeKeySpec = new PBEKeySpec(StaticHelper.bytesToBase64(key).toCharArray(), key, 1000, 128);
|
|
59
|
-
SecretKey pbeKey = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(pbeKeySpec);
|
|
60
|
-
return new SecretKeySpec(pbeKey.getEncoded(), "AES");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
package land.fx.fula;
|
|
2
|
+
|
|
3
|
+
import android.util.Base64;
|
|
4
|
+
|
|
5
|
+
import java.io.UnsupportedEncodingException;
|
|
6
|
+
import java.nio.charset.StandardCharsets;
|
|
7
|
+
import java.security.InvalidAlgorithmParameterException;
|
|
8
|
+
import java.security.InvalidKeyException;
|
|
9
|
+
import java.security.NoSuchAlgorithmException;
|
|
10
|
+
import java.security.spec.InvalidKeySpecException;
|
|
11
|
+
import java.security.SecureRandom;
|
|
12
|
+
import java.nio.ByteBuffer;
|
|
13
|
+
import java.security.spec.InvalidParameterSpecException;
|
|
14
|
+
|
|
15
|
+
import javax.crypto.BadPaddingException;
|
|
16
|
+
import javax.crypto.Cipher;
|
|
17
|
+
import javax.crypto.IllegalBlockSizeException;
|
|
18
|
+
import javax.crypto.NoSuchPaddingException;
|
|
19
|
+
import javax.crypto.SecretKey;
|
|
20
|
+
import javax.crypto.SecretKeyFactory;
|
|
21
|
+
import javax.crypto.spec.PBEKeySpec;
|
|
22
|
+
import javax.crypto.spec.SecretKeySpec;
|
|
23
|
+
import javax.crypto.spec.GCMParameterSpec;
|
|
24
|
+
|
|
25
|
+
public class Cryptography {
|
|
26
|
+
public static String encryptMsg(String message, SecretKey secret, byte[] iv)
|
|
27
|
+
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {
|
|
28
|
+
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
|
29
|
+
if (iv == null || iv.length == 0) {
|
|
30
|
+
iv = new byte[12]; // Ensure this is randomly generated for each encryption.
|
|
31
|
+
new SecureRandom().nextBytes(iv);
|
|
32
|
+
}
|
|
33
|
+
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
|
|
34
|
+
cipher.init(Cipher.ENCRYPT_MODE, secret, spec);
|
|
35
|
+
byte[] cipherText = cipher.doFinal(message.getBytes(StandardCharsets.UTF_8));
|
|
36
|
+
ByteBuffer byteBuffer = ByteBuffer.allocate(iv.length + cipherText.length);
|
|
37
|
+
byteBuffer.put(iv);
|
|
38
|
+
byteBuffer.put(cipherText);
|
|
39
|
+
return Base64.encodeToString(byteBuffer.array(), Base64.NO_WRAP);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static String decryptMsg(String cipherText, SecretKey secret)
|
|
43
|
+
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
|
44
|
+
ByteBuffer byteBuffer = ByteBuffer.wrap(Base64.decode(cipherText, Base64.NO_WRAP));
|
|
45
|
+
byte[] iv = new byte[12];
|
|
46
|
+
byteBuffer.get(iv);
|
|
47
|
+
byte[] cipherBytes = new byte[byteBuffer.remaining()];
|
|
48
|
+
byteBuffer.get(cipherBytes);
|
|
49
|
+
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
|
50
|
+
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
|
|
51
|
+
cipher.init(Cipher.DECRYPT_MODE, secret, spec);
|
|
52
|
+
String decryptString = new String(cipher.doFinal(cipherBytes), StandardCharsets.UTF_8);
|
|
53
|
+
return decryptString;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public static SecretKey generateKey(byte[] key)
|
|
57
|
+
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
|
58
|
+
PBEKeySpec pbeKeySpec = new PBEKeySpec(StaticHelper.bytesToBase64(key).toCharArray(), key, 1000, 128);
|
|
59
|
+
SecretKey pbeKey = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(pbeKeySpec);
|
|
60
|
+
return new SecretKeySpec(pbeKey.getEncoded(), "AES");
|
|
61
|
+
}
|
|
62
|
+
}
|