@functionland/react-native-fula 1.14.7 → 1.19.0
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/README.md +226 -214
- package/android/build.gradle +110 -110
- package/android/gradle.properties +5 -5
- 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 +1435 -1466
- 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 +49 -49
- package/ios/Fula-Bridging-Header.h +3 -3
- package/ios/Fula.mm +197 -199
- package/ios/Fula.swift +1221 -1221
- package/ios/UserDataHelper.swift +143 -143
- package/lib/commonjs/index.js +2 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interfaces/augment-api-errors.js +4 -0
- package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -0
- package/lib/commonjs/interfaces/augment-api-rpc.js +4 -0
- package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -0
- package/lib/commonjs/interfaces/augment-api-runtime.js +4 -0
- package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -0
- package/lib/commonjs/interfaces/augment-api.js +10 -0
- package/lib/commonjs/interfaces/augment-api.js.map +1 -0
- package/lib/commonjs/interfaces/augment-types.js +4 -0
- package/lib/commonjs/interfaces/augment-types.js.map +1 -0
- package/lib/commonjs/interfaces/fulaNativeModule.js +1 -2
- package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/commonjs/interfaces/index.js +6 -0
- package/lib/commonjs/interfaces/index.js.map +1 -0
- package/lib/commonjs/interfaces/{api-lookup.js → lookup.js} +623 -382
- package/lib/commonjs/interfaces/lookup.js.map +1 -0
- package/lib/commonjs/interfaces/registry.js +4 -0
- package/lib/commonjs/interfaces/registry.js.map +1 -0
- package/lib/commonjs/interfaces/types-lookup.js +4 -0
- package/lib/commonjs/interfaces/types-lookup.js.map +1 -0
- package/lib/commonjs/interfaces/types.js +4 -0
- package/lib/commonjs/interfaces/types.js.map +1 -0
- package/lib/commonjs/protocols/blockchain.js +123 -76
- package/lib/commonjs/protocols/blockchain.js.map +1 -1
- package/lib/commonjs/protocols/chain-api.js +151 -37
- package/lib/commonjs/protocols/chain-api.js.map +1 -1
- package/lib/commonjs/protocols/fula.js +195 -99
- package/lib/commonjs/protocols/fula.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-errors.js +9 -0
- package/lib/module/interfaces/augment-api-errors.js.map +1 -0
- package/lib/module/interfaces/augment-api-rpc.js +9 -0
- package/lib/module/interfaces/augment-api-rpc.js.map +1 -0
- package/lib/module/interfaces/augment-api-runtime.js +9 -0
- package/lib/module/interfaces/augment-api-runtime.js.map +1 -0
- package/lib/module/interfaces/augment-api.js +11 -0
- package/lib/module/interfaces/augment-api.js.map +1 -0
- package/lib/module/interfaces/augment-types.js +9 -0
- package/lib/module/interfaces/augment-types.js.map +1 -0
- package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/module/interfaces/index.js +5 -0
- package/lib/module/interfaces/index.js.map +1 -0
- package/lib/module/interfaces/{api-lookup.js → lookup.js} +622 -380
- package/lib/module/interfaces/lookup.js.map +1 -0
- package/lib/module/interfaces/registry.js +9 -0
- package/lib/module/interfaces/registry.js.map +1 -0
- package/lib/module/interfaces/types-lookup.js +9 -0
- package/lib/module/interfaces/types-lookup.js.map +1 -0
- package/lib/module/interfaces/types.js +3 -0
- package/lib/module/interfaces/types.js.map +1 -0
- package/lib/module/protocols/blockchain.js +120 -75
- package/lib/module/protocols/blockchain.js.map +1 -1
- package/lib/module/protocols/chain-api.js +142 -31
- package/lib/module/protocols/chain-api.js.map +1 -1
- package/lib/module/protocols/fula.js +191 -99
- package/lib/module/protocols/fula.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/lib/typescript/interfaces/augment-api-errors.d.ts +442 -0
- package/lib/typescript/interfaces/augment-api-errors.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-api-rpc.d.ts +680 -0
- package/lib/typescript/interfaces/augment-api-rpc.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-api-runtime.d.ts +248 -0
- package/lib/typescript/interfaces/augment-api-runtime.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-api.d.ts +8 -0
- package/lib/typescript/interfaces/augment-api.d.ts.map +1 -0
- package/lib/typescript/interfaces/augment-types.d.ts +1224 -0
- package/lib/typescript/interfaces/augment-types.d.ts.map +1 -0
- package/lib/typescript/interfaces/fulaNativeModule.d.ts +7 -3
- package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -1
- package/lib/typescript/interfaces/index.d.ts +1 -0
- package/lib/typescript/interfaces/index.d.ts.map +1 -0
- package/lib/typescript/interfaces/{api-lookup.d.ts → lookup.d.ts} +441 -199
- package/lib/typescript/interfaces/lookup.d.ts.map +1 -0
- package/lib/typescript/interfaces/registry.d.ts +146 -0
- package/lib/typescript/interfaces/registry.d.ts.map +1 -0
- package/lib/typescript/interfaces/types-lookup.d.ts +1910 -0
- package/lib/typescript/interfaces/types-lookup.d.ts.map +1 -0
- package/lib/typescript/interfaces/types.d.ts +1 -0
- package/lib/typescript/interfaces/types.d.ts.map +1 -0
- package/lib/typescript/protocols/blockchain.d.ts +5 -3
- package/lib/typescript/protocols/blockchain.d.ts.map +1 -1
- package/lib/typescript/protocols/chain-api.d.ts +5 -0
- package/lib/typescript/protocols/chain-api.d.ts.map +1 -1
- package/lib/typescript/protocols/fula.d.ts +16 -0
- package/lib/typescript/protocols/fula.d.ts.map +1 -1
- package/lib/typescript/types/blockchain.d.ts +6 -0
- package/lib/typescript/types/blockchain.d.ts.map +1 -1
- package/package.json +178 -172
- package/react-native-fula.podspec +47 -47
- package/src/index.tsx +4 -4
- package/src/interfaces/augment-api-errors.ts +449 -0
- package/src/interfaces/augment-api-rpc.ts +617 -0
- package/src/interfaces/augment-api-runtime.ts +224 -0
- package/src/interfaces/augment-api.ts +10 -0
- package/src/interfaces/augment-types.ts +1230 -0
- package/src/interfaces/fulaNativeModule.ts +130 -122
- package/src/interfaces/index.ts +4 -0
- package/src/interfaces/{api-lookup.ts → lookup.ts} +1889 -1647
- package/src/interfaces/registry.ts +152 -0
- package/src/interfaces/types-lookup.ts +2043 -0
- package/src/interfaces/types.ts +3 -0
- package/src/protocols/blockchain.ts +549 -504
- package/src/protocols/chain-api.ts +148 -24
- package/src/protocols/fula.ts +419 -314
- package/src/protocols/fxblox.ts +49 -49
- package/src/types/blockchain.ts +89 -81
- package/src/types/fxblox.ts +8 -8
- package/ios/Fula.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/Fula.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Fula.xcodeproj/project.xcworkspace/xcuserdata/user246549.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Fula.xcodeproj/xcuserdata/user246549.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/lib/commonjs/interfaces/api-lookup.js.map +0 -1
- package/lib/module/interfaces/api-lookup.js.map +0 -1
- package/lib/typescript/interfaces/api-lookup.d.ts.map +0 -1
package/android/build.gradle
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
buildscript {
|
|
2
|
-
repositories {
|
|
3
|
-
google()
|
|
4
|
-
mavenCentral()
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
dependencies {
|
|
8
|
-
classpath "com.android.tools.build:gradle:7.2.
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
def isNewArchitectureEnabled() {
|
|
13
|
-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
apply plugin: "com.android.library"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
20
|
-
|
|
21
|
-
if (isNewArchitectureEnabled()) {
|
|
22
|
-
apply plugin: "com.facebook.react"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
def getExtOrDefault(name) {
|
|
26
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Fula_" + name]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
def getExtOrIntegerDefault(name) {
|
|
30
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Fula_" + name]).toInteger()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
def supportsNamespace() {
|
|
34
|
-
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
35
|
-
def major = parsed[0].toInteger()
|
|
36
|
-
def minor = parsed[1].toInteger()
|
|
37
|
-
|
|
38
|
-
// Namespace support was added in 7.3.0
|
|
39
|
-
if (major == 7 && minor >= 3) {
|
|
40
|
-
return true
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return major >= 8
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
android {
|
|
47
|
-
if (supportsNamespace()) {
|
|
48
|
-
namespace "land.fx.fula"
|
|
49
|
-
|
|
50
|
-
sourceSets {
|
|
51
|
-
main {
|
|
52
|
-
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
58
|
-
|
|
59
|
-
defaultConfig {
|
|
60
|
-
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
61
|
-
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
62
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
63
|
-
}
|
|
64
|
-
buildTypes {
|
|
65
|
-
release {
|
|
66
|
-
minifyEnabled false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
lintOptions {
|
|
71
|
-
disable "GradleCompatible"
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
compileOptions {
|
|
75
|
-
sourceCompatibility JavaVersion.VERSION_1_8
|
|
76
|
-
targetCompatibility JavaVersion.VERSION_1_8
|
|
77
|
-
}
|
|
78
|
-
ndkVersion '25.1.8937393'
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
repositories {
|
|
82
|
-
mavenLocal()
|
|
83
|
-
google()
|
|
84
|
-
jcenter()
|
|
85
|
-
mavenCentral()
|
|
86
|
-
|
|
87
|
-
// Add this repo to get go-fula package
|
|
88
|
-
maven { url 'https://jitpack.io' }
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
dependencies {
|
|
93
|
-
// For < 0.71, this will be from the local maven repo
|
|
94
|
-
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
95
|
-
//noinspection GradleDynamicVersion
|
|
96
|
-
implementation "com.facebook.react:react-native:+"
|
|
97
|
-
implementation 'com.github.functionland:fula-build-aar:v1.
|
|
98
|
-
implementation 'com.github.functionland:wnfs-android:v1.8.
|
|
99
|
-
implementation 'commons-io:commons-io:20030203.000550'
|
|
100
|
-
implementation 'commons-codec:commons-codec:1.15'
|
|
101
|
-
// implementation files('mobile.aar')
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (isNewArchitectureEnabled()) {
|
|
105
|
-
react {
|
|
106
|
-
jsRootDir = file("../src/")
|
|
107
|
-
libraryName = "Fula"
|
|
108
|
-
codegenJavaPackageName = "land.fx.fula"
|
|
109
|
-
}
|
|
110
|
-
}
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath "com.android.tools.build:gradle:7.2.2"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def isNewArchitectureEnabled() {
|
|
13
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
apply plugin: "com.android.library"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
20
|
+
|
|
21
|
+
if (isNewArchitectureEnabled()) {
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def getExtOrDefault(name) {
|
|
26
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Fula_" + name]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def getExtOrIntegerDefault(name) {
|
|
30
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Fula_" + name]).toInteger()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def supportsNamespace() {
|
|
34
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
35
|
+
def major = parsed[0].toInteger()
|
|
36
|
+
def minor = parsed[1].toInteger()
|
|
37
|
+
|
|
38
|
+
// Namespace support was added in 7.3.0
|
|
39
|
+
if (major == 7 && minor >= 3) {
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return major >= 8
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
android {
|
|
47
|
+
if (supportsNamespace()) {
|
|
48
|
+
namespace "land.fx.fula"
|
|
49
|
+
|
|
50
|
+
sourceSets {
|
|
51
|
+
main {
|
|
52
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
58
|
+
|
|
59
|
+
defaultConfig {
|
|
60
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
61
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
62
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
63
|
+
}
|
|
64
|
+
buildTypes {
|
|
65
|
+
release {
|
|
66
|
+
minifyEnabled false
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
lintOptions {
|
|
71
|
+
disable "GradleCompatible"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
compileOptions {
|
|
75
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
76
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
77
|
+
}
|
|
78
|
+
ndkVersion '25.1.8937393'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
repositories {
|
|
82
|
+
mavenLocal()
|
|
83
|
+
google()
|
|
84
|
+
jcenter()
|
|
85
|
+
mavenCentral()
|
|
86
|
+
|
|
87
|
+
// Add this repo to get go-fula package
|
|
88
|
+
maven { url 'https://jitpack.io' }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
dependencies {
|
|
93
|
+
// For < 0.71, this will be from the local maven repo
|
|
94
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
95
|
+
//noinspection GradleDynamicVersion
|
|
96
|
+
implementation "com.facebook.react:react-native:+"
|
|
97
|
+
implementation 'com.github.functionland:fula-build-aar:v1.19.0' // From jitpack.io
|
|
98
|
+
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
|
|
99
|
+
implementation 'commons-io:commons-io:20030203.000550'
|
|
100
|
+
implementation 'commons-codec:commons-codec:1.15'
|
|
101
|
+
// implementation files('mobile.aar')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (isNewArchitectureEnabled()) {
|
|
105
|
+
react {
|
|
106
|
+
jsRootDir = file("../src/")
|
|
107
|
+
libraryName = "Fula"
|
|
108
|
+
codegenJavaPackageName = "land.fx.fula"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Fula_kotlinVersion=1.7.0
|
|
2
|
-
Fula_minSdkVersion=
|
|
3
|
-
Fula_targetSdkVersion=31
|
|
4
|
-
Fula_compileSdkVersion=31
|
|
5
|
-
Fula_ndkversion=21.4.7075529
|
|
1
|
+
Fula_kotlinVersion=1.7.0
|
|
2
|
+
Fula_minSdkVersion=26
|
|
3
|
+
Fula_targetSdkVersion=31
|
|
4
|
+
Fula_compileSdkVersion=31
|
|
5
|
+
Fula_ndkversion=21.4.7075529
|
|
@@ -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
|
+
}
|