@functionland/react-native-fula 1.55.0 → 1.55.1

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.
Files changed (98) hide show
  1. package/LICENSE +20 -20
  2. package/android/build.gradle +114 -115
  3. package/android/gradle.properties +8 -8
  4. package/android/src/main/AndroidManifest.xml +3 -3
  5. package/android/src/main/AndroidManifestNew.xml +2 -2
  6. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  7. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  8. package/android/src/main/java/land/fx/fula/FulaModule.java +1991 -1868
  9. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  10. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  11. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  12. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  13. package/ios/Cryptography.swift +59 -59
  14. package/ios/Fula-Bridging-Header.h +3 -3
  15. package/ios/UserDataHelper.swift +143 -143
  16. package/lib/commonjs/index.js +3 -1
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/interfaces/augment-api-consts.js.map +1 -1
  19. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -1
  20. package/lib/commonjs/interfaces/augment-api-events.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-query.js.map +1 -1
  22. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -1
  23. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -1
  24. package/lib/commonjs/interfaces/augment-api-tx.js.map +1 -1
  25. package/lib/commonjs/interfaces/augment-api.js.map +1 -1
  26. package/lib/commonjs/interfaces/augment-types.js.map +1 -1
  27. package/lib/commonjs/interfaces/definitions.js.map +1 -1
  28. package/lib/commonjs/interfaces/defintions.js.map +1 -1
  29. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  30. package/lib/commonjs/interfaces/index.js.map +1 -1
  31. package/lib/commonjs/interfaces/lookup.js +300 -300
  32. package/lib/commonjs/interfaces/lookup.js.map +1 -1
  33. package/lib/commonjs/interfaces/registry.js.map +1 -1
  34. package/lib/commonjs/interfaces/types-lookup.js.map +1 -1
  35. package/lib/commonjs/interfaces/types.js.map +1 -1
  36. package/lib/commonjs/protocols/blockchain.js +66 -66
  37. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  38. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  39. package/lib/commonjs/protocols/fula.js.map +1 -1
  40. package/lib/commonjs/protocols/fx-ai.js +103 -0
  41. package/lib/commonjs/protocols/fx-ai.js.map +1 -0
  42. package/lib/commonjs/protocols/fxblox.js +3 -3
  43. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  44. package/lib/commonjs/types/blockchain.js.map +1 -1
  45. package/lib/commonjs/types/fxblox.js.map +1 -1
  46. package/lib/module/index.js +1 -0
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/interfaces/augment-api-consts.js.map +1 -1
  49. package/lib/module/interfaces/augment-api-errors.js.map +1 -1
  50. package/lib/module/interfaces/augment-api-events.js.map +1 -1
  51. package/lib/module/interfaces/augment-api-query.js.map +1 -1
  52. package/lib/module/interfaces/augment-api-rpc.js.map +1 -1
  53. package/lib/module/interfaces/augment-api-runtime.js.map +1 -1
  54. package/lib/module/interfaces/augment-api-tx.js.map +1 -1
  55. package/lib/module/interfaces/augment-api.js.map +1 -1
  56. package/lib/module/interfaces/augment-types.js.map +1 -1
  57. package/lib/module/interfaces/definitions.js.map +1 -1
  58. package/lib/module/interfaces/defintions.js.map +1 -1
  59. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  60. package/lib/module/interfaces/index.js.map +1 -1
  61. package/lib/module/interfaces/lookup.js +300 -300
  62. package/lib/module/interfaces/lookup.js.map +1 -1
  63. package/lib/module/interfaces/registry.js.map +1 -1
  64. package/lib/module/interfaces/types-lookup.js.map +1 -1
  65. package/lib/module/interfaces/types.js.map +1 -1
  66. package/lib/module/protocols/blockchain.js +66 -66
  67. package/lib/module/protocols/blockchain.js.map +1 -1
  68. package/lib/module/protocols/chain-api.js.map +1 -1
  69. package/lib/module/protocols/fula.js.map +1 -1
  70. package/lib/module/protocols/fx-ai.js +93 -0
  71. package/lib/module/protocols/fx-ai.js.map +1 -0
  72. package/lib/module/protocols/fxblox.js +3 -3
  73. package/lib/module/protocols/fxblox.js.map +1 -1
  74. package/lib/module/types/blockchain.js.map +1 -1
  75. package/lib/module/types/fxblox.js.map +1 -1
  76. package/package.json +176 -176
  77. package/react-native-fula.podspec +47 -47
  78. package/src/index.tsx +5 -4
  79. package/src/interfaces/augment-api-consts.ts +273 -273
  80. package/src/interfaces/augment-api-errors.ts +474 -474
  81. package/src/interfaces/augment-api-events.ts +448 -448
  82. package/src/interfaces/augment-api-query.ts +466 -466
  83. package/src/interfaces/augment-api-rpc.ts +617 -617
  84. package/src/interfaces/augment-api-runtime.ts +223 -223
  85. package/src/interfaces/augment-api-tx.ts +709 -709
  86. package/src/interfaces/augment-api.ts +9 -9
  87. package/src/interfaces/augment-types.ts +1322 -1322
  88. package/src/interfaces/definitions.ts +1 -1
  89. package/src/interfaces/defintions.ts +1 -1
  90. package/src/interfaces/fulaNativeModule.ts +175 -168
  91. package/src/interfaces/index.ts +3 -3
  92. package/src/interfaces/lookup.ts +2011 -2011
  93. package/src/interfaces/registry.ts +163 -163
  94. package/src/interfaces/types-lookup.ts +2165 -2165
  95. package/src/interfaces/types.ts +2 -2
  96. package/src/protocols/blockchain.ts +644 -644
  97. package/src/protocols/fx-ai.ts +111 -0
  98. package/src/protocols/fxblox.ts +443 -443
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.
@@ -1,115 +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.2.2"
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
- jcenter()
90
- mavenCentral()
91
-
92
- // Add this repo to get go-fula package
93
- maven { url 'https://jitpack.io' }
94
- }
95
-
96
-
97
- dependencies {
98
- // For < 0.71, this will be from the local maven repo
99
- // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
100
- //noinspection GradleDynamicVersion
101
- implementation "com.facebook.react:react-android:+"
102
- implementation 'com.github.functionland:fula-build-aar:v1.55.0' // From jitpack.io
103
- implementation 'com.github.functionland:wnfs-android:v1.8.2' // From jitpack.io
104
- implementation 'commons-io:commons-io:20030203.000550'
105
- implementation 'commons-codec:commons-codec:1.15'
106
- // implementation files('mobile.aar')
107
- }
108
-
109
- if (isNewArchitectureEnabled()) {
110
- react {
111
- jsRootDir = file("../src/")
112
- libraryName = "Fula"
113
- codegenJavaPackageName = "land.fx.fula"
114
- }
115
- }
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.2.2"
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.9' // 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=33
4
- Fula_compileSdkVersion=33
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=33
4
+ Fula_compileSdkVersion=33
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
+ }