Browse Source

Generating salt key and secret key by concatenating id by 16 times and taking last and first 16 length respectively

Khubaib 1 week ago
parent
commit
15b89b7062

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

@@ -58,19 +58,20 @@ class Utils {
 
         fun customSaltKey(userinfo: UserInfo) : String {
             val id = userinfo.id
-            val email = userinfo.email
-            val saltKey = "${id}_${email}_${id}"
-            val filterSaltKey = saltKey.replace("[@.]".toRegex(), "")
-            val encodedSaltKey = Base64.encodeToString(filterSaltKey.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
-            val salt16Length = encodedSaltKey.take(16)
-            return salt16Length
+//            val email = userinfo.email
+//            val saltKey = "${id}_${email}_${id}"
+//            val filterSaltKey = saltKey.replace("[@.]".toRegex(), "")
+//            val encodedSaltKey = Base64.encodeToString(filterSaltKey.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
+//            val salt16Length = encodedSaltKey.take(16)
+
+            val saltKey = id.toString().repeat(16).takeLast(16)
+            return saltKey
         }
 
-        fun customPassword(password: String) : String {
-            val reversedPassword = "$password${password.reversed()}"
-            val encodedPassword = Base64.encodeToString(reversedPassword.toByteArray(Charsets.UTF_8), Base64.DEFAULT)
-            val password16Length = encodedPassword.take(16)
-            return password16Length
+        fun customSecretKey(userinfo: UserInfo) : String {
+            val id = userinfo.id
+            val secretKey = id.toString().repeat(16).take(16)
+            return secretKey
         }
     }
 }

+ 9 - 0
app/src/main/java/com/fastest/pass/helpers/BasePreferenceHelper.kt

@@ -60,6 +60,14 @@ class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
         return getStringPreference(context, KEY_FILENAME, KEY_PASSWORD)
     }
 
+    fun saveCustomSecretKey(secretKey: String) {
+        putStringPreference(context, KEY_FILENAME, KEY_SECRET_KEY, secretKey)
+    }
+
+    fun getCustomSecretKey(): String? {
+        return getStringPreference(context, KEY_FILENAME, KEY_SECRET_KEY)
+    }
+
     companion object {
         private const val KEY_FILENAME = "file_fastestpass"
         private const val KEY_IS_LOGGED_IN = "key_isloggedin"
@@ -67,5 +75,6 @@ class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
         private const val KEY_USERINFO = "key_userinfo"
         private const val KEY_SALT_KEY = "key_salt_key"
         private const val KEY_PASSWORD = "key_password"
+        private const val KEY_SECRET_KEY = "key_secret_key"
     }
 }

+ 2 - 0
app/src/main/java/com/fastest/pass/login/presentation/ui/LoginFragment.kt

@@ -84,6 +84,8 @@ class LoginFragment : BaseFragment() {
                                     basePreferenceHelper.saveUserInfo(it.userinfo)
                                     val saltKey = Utils.customSaltKey(it.userinfo)
                                     basePreferenceHelper.saveCustomSaltKey(saltKey)
+                                    val secretKey = Utils.customSecretKey(it.userinfo)
+                                    basePreferenceHelper.saveCustomSecretKey(secretKey)
                                     basePreferenceHelper.savePassword(passwordLogin)
                                     viewmodel.navigateTo(LoginRoute.OpenDashBoardScreen)
                                 }

+ 2 - 0
app/src/main/java/com/fastest/pass/signup/presentation/ui/SignUpFragment.kt

@@ -67,6 +67,8 @@ class SignUpFragment : BaseFragment() {
                                 it1 -> basePreferenceHelper.saveUserInfo(it1)
                                 val saltKey = Utils.customSaltKey(it1)
                                 basePreferenceHelper.saveCustomSaltKey(saltKey)
+                                val secretKey = Utils.customSecretKey(it1)
+                                basePreferenceHelper.saveCustomSecretKey(secretKey)
                                 basePreferenceHelper.savePassword(passwordSU)
                             }
                             viewmodel.navigateTo(SignUpRoute.OpenDashBoardScreen)