Explorar o código

Updated encrption and decryption logic for generating secret key and salt key

Khubaib hai 1 semana
pai
achega
82afa53c33
Modificáronse 1 ficheiros con 4 adicións e 4 borrados
  1. 4 4
      app/src/main/java/com/fastest/pass/app/Utils.kt

+ 4 - 4
app/src/main/java/com/fastest/pass/app/Utils.kt

@@ -42,10 +42,10 @@ class Utils {
             return encryptedDataBase64
         }
 
-        fun decryptData(ivBase64: String, encryptedBase64: String, secretKeyString: String) : String {
-            val iv = Base64.decode(ivBase64, Base64.DEFAULT)
+        fun decryptData(ivKey: String, encryptedBase64: String, secretKeyString: String) : String {
+//            val iv = Base64.decode(ivBase64, Base64.DEFAULT)
             val encryptedBytes = Base64.decode(encryptedBase64, Base64.DEFAULT)
-            val ivSpec = IvParameterSpec(iv)
+            val ivSpec = IvParameterSpec(ivKey.toByteArray(Charsets.UTF_8))
             val secKey: SecretKey = SecretKeySpec(secretKeyString.toByteArray(Charsets.UTF_8), "AES")
 
             val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
@@ -64,7 +64,7 @@ class Utils {
 //            val encodedSaltKey = Base64.encodeToString(filterSaltKey.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
 //            val salt16Length = encodedSaltKey.take(16)
 
-            val saltKey = id.toString().repeat(16).takeLast(16)
+            val saltKey = id.toString().repeat(16).reversed().takeLast(16)
             return saltKey
         }