@onekeyfe/react-native-aes-crypto 3.0.8 → 3.0.9

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.
@@ -148,7 +148,7 @@ class AesCryptoModule(reactContext: ReactApplicationContext) :
148
148
 
149
149
  private fun shaX(data: String, algorithm: String): String {
150
150
  val md = MessageDigest.getInstance(algorithm)
151
- md.update(data.toByteArray())
151
+ md.update(Hex.decode(data))
152
152
  return bytesToHex(md.digest())
153
153
  }
154
154
 
@@ -160,13 +160,13 @@ class AesCryptoModule(reactContext: ReactApplicationContext) :
160
160
  else -> SHA512Digest()
161
161
  }
162
162
  val gen = PKCS5S2ParametersGenerator(algorithmDigest)
163
- gen.init(pwd.toByteArray(Charsets.UTF_8), salt.toByteArray(Charsets.UTF_8), cost)
163
+ gen.init(Hex.decode(pwd), Hex.decode(salt), cost)
164
164
  val key = (gen.generateDerivedParameters(length) as KeyParameter).key
165
165
  return bytesToHex(key)
166
166
  }
167
167
 
168
168
  private fun hmacX(text: String, key: String, algorithm: String): String {
169
- val contentData = text.toByteArray(Charsets.UTF_8)
169
+ val contentData = Hex.decode(text)
170
170
  val akHexData = Hex.decode(key)
171
171
  val mac = Mac.getInstance(algorithm)
172
172
  val secretKey = SecretKeySpec(akHexData, algorithm)
@@ -182,8 +182,8 @@ class AesCryptoModule(reactContext: ReactApplicationContext) :
182
182
  val cipher = Cipher.getInstance(algorithm)
183
183
  val ivSpec = if (hexIv == null || hexIv.isEmpty()) emptyIvSpec else IvParameterSpec(Hex.decode(hexIv))
184
184
  cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec)
185
- val encrypted = cipher.doFinal(text.toByteArray(Charsets.UTF_8))
186
- return Base64.encodeToString(encrypted, Base64.NO_WRAP)
185
+ val encrypted = cipher.doFinal(Hex.decode(text))
186
+ return bytesToHex(encrypted)
187
187
  }
188
188
 
189
189
  private fun decryptImpl(ciphertext: String, hexKey: String, hexIv: String?, algorithm: String): String? {
@@ -194,7 +194,7 @@ class AesCryptoModule(reactContext: ReactApplicationContext) :
194
194
  val cipher = Cipher.getInstance(algorithm)
195
195
  val ivSpec = if (hexIv == null || hexIv.isEmpty()) emptyIvSpec else IvParameterSpec(Hex.decode(hexIv))
196
196
  cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec)
197
- val decrypted = cipher.doFinal(Base64.decode(ciphertext, Base64.NO_WRAP))
198
- return String(decrypted, Charsets.UTF_8)
197
+ val decrypted = cipher.doFinal(Hex.decode(ciphertext))
198
+ return bytesToHex(decrypted)
199
199
  }
200
200
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-aes-crypto",
3
- "version": "3.0.8",
3
+ "version": "3.0.9",
4
4
  "description": "react-native-aes-crypto",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",