@functionland/react-native-fula 1.54.8 → 1.54.10
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/ios/Cryptography.swift +48 -38
- package/ios/Fula.mm +4 -2
- package/ios/Fula.swift +372 -255
- package/package.json +1 -1
- package/react-native-fula.podspec +1 -1
package/ios/Cryptography.swift
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
-
import CommonCrypto
|
|
3
2
|
import CryptoSwift
|
|
4
3
|
import os.log
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
public
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let aes = try! AES(key: secretKey, blockMode: ECB(), padding: .pkcs5)
|
|
13
|
-
OSLog.viewCycle.info("ReactNative encryptMsg aes")
|
|
14
|
-
let encrypted = try! aes.encrypt(message)
|
|
15
|
-
OSLog.viewCycle.info("ReactNative encryptMsg encrypted")
|
|
16
|
-
do{
|
|
17
|
-
let data = Data(encrypted).base64EncodedString()
|
|
18
|
-
OSLog.viewCycle.info("ReactNative encryptMsg: \(data)")
|
|
19
|
-
return data
|
|
20
|
-
} catch let error {
|
|
21
|
-
OSLog.viewCycle.info("ReactNative encryptMsg error: \(error.localizedDescription)")
|
|
22
|
-
throw error
|
|
5
|
+
public class Cryptography {
|
|
6
|
+
// AES/GCM Encryption with IV handling
|
|
7
|
+
public static func encryptMsg(_ message: [UInt8], _ secretKey: [UInt8], _ providedIv: [UInt8]? = nil) throws -> String {
|
|
8
|
+
var iv = providedIv ?? [UInt8](repeating: 0, count: 12) // Default IV value
|
|
9
|
+
if iv.isEmpty {
|
|
10
|
+
iv = AES.randomIV(12) // Generate a random IV if not provided or if empty
|
|
23
11
|
}
|
|
12
|
+
|
|
13
|
+
let gcm = GCM(iv: iv, mode: .combined)
|
|
14
|
+
let aes = try AES(key: secretKey, blockMode: gcm, padding: .noPadding)
|
|
15
|
+
|
|
16
|
+
let encrypted = try aes.encrypt(message)
|
|
17
|
+
let encryptedDataWithIv = Data(iv + encrypted) // Prepend IV to the encrypted data
|
|
18
|
+
return encryptedDataWithIv.base64EncodedString()
|
|
24
19
|
}
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
throws ->
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
// AES/GCM Decryption with IV extracted from the beginning of the cipherText
|
|
22
|
+
public static func decryptMsg(_ cipherText: String, _ secretKey: [UInt8]) throws -> [UInt8] {
|
|
23
|
+
guard let encryptedDataWithIv = Data(base64Encoded: cipherText) else {
|
|
24
|
+
throw NSError(domain: "DecryptionError", code: -1, userInfo: nil)
|
|
25
|
+
}
|
|
26
|
+
let iv = Array(encryptedDataWithIv.prefix(12)) // Extract IV (first 12 bytes)
|
|
27
|
+
let encryptedData = Array(encryptedDataWithIv.dropFirst(12)) // The rest is the encrypted data
|
|
28
|
+
|
|
29
|
+
let gcm = GCM(iv: iv, mode: .combined)
|
|
30
|
+
let aes = try AES(key: secretKey, blockMode: gcm, padding: .noPadding)
|
|
31
|
+
|
|
32
|
+
let decrypted = try aes.decrypt(encryptedData)
|
|
33
|
+
return decrypted
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
throws ->
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
// Key Generation matching Java's logic
|
|
37
|
+
public static func generateKey(_ identity: Data) throws -> Data {
|
|
38
|
+
// Transform identity to base64 string to mimic Java's behavior
|
|
39
|
+
let passwordString = identity.base64EncodedString()
|
|
40
|
+
let passwordData = Array(passwordString.utf8) // Convert to byte array
|
|
41
|
+
|
|
42
|
+
// Use identity itself as salt for simplicity to mimic Java behavior
|
|
43
|
+
let salt = Array(identity)
|
|
44
|
+
|
|
45
|
+
do {
|
|
46
|
+
let key = try PKCS5.PBKDF2(
|
|
47
|
+
password: passwordData,
|
|
48
|
+
salt: salt,
|
|
49
|
+
iterations: 1000, // Adjust the iteration count as needed
|
|
50
|
+
keyLength: 16, // AES-128
|
|
51
|
+
variant: .sha256
|
|
52
|
+
).calculate()
|
|
53
|
+
|
|
54
|
+
return Data(key)
|
|
55
|
+
} catch {
|
|
56
|
+
throw error // Propagate error
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
59
|
}
|
package/ios/Fula.mm
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
@interface RCT_EXTERN_MODULE(FulaModule, NSObject)
|
|
4
4
|
|
|
5
|
-
RCT_EXTERN_METHOD(registerLifecycleListener)
|
|
5
|
+
RCT_EXTERN_METHOD(registerLifecycleListener:(RCTPromiseResolveBlock)resolve
|
|
6
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
6
7
|
|
|
7
8
|
RCT_EXTERN_METHOD(checkConnection: (nonnull NSNumber *) timeout
|
|
8
9
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
@@ -189,7 +190,8 @@ RCT_EXTERN_METHOD(getFolderSize:(NSString *)folderPath
|
|
|
189
190
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
190
191
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
191
192
|
|
|
192
|
-
RCT_EXTERN_METHOD(getDatastoreSize:(RCTPromiseResolveBlock)resolve
|
|
193
|
+
RCT_EXTERN_METHOD(getDatastoreSize:(RCTPromiseResolveBlock)resolve
|
|
194
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
193
195
|
|
|
194
196
|
+ (BOOL)requiresMainQueueSetup
|
|
195
197
|
{
|