@@ -82,18 +82,20 @@ object KeyStoreManagerUtils {
8282 fun decryptData (key : String ): String? {
8383 var result: String? = null
8484 try {
85- val sharedPreferenceIds = sharedPreferences.all
86- sharedPreferenceIds.forEach {
87- if (it.key.contains(key)) {
88- result = sharedPreferences.getString(it.key, " " )
85+ if (this ::sharedPreferences.isInitialized) {
86+ val sharedPreferenceIds = sharedPreferences.all
87+ sharedPreferenceIds.forEach {
88+ if (it.key.contains(key)) {
89+ result = sharedPreferences.getString(it.key, " " )
90+ }
8991 }
92+ if (result == null ) return null
93+ val encryptedPairData = result?.let { getEncryptedDataPair(it) }
94+ val cipher = Cipher .getInstance(TRANSFORMATION )
95+ val keySpec = IvParameterSpec (encryptedPairData?.first)
96+ cipher.init (Cipher .DECRYPT_MODE , getKey(), keySpec)
97+ return cipher.doFinal(encryptedPairData?.second).toString(UTF_8 )
9098 }
91- if (result == null ) return null
92- val encryptedPairData = result?.let { getEncryptedDataPair(it) }
93- val cipher = Cipher .getInstance(TRANSFORMATION )
94- val keySpec = IvParameterSpec (encryptedPairData?.first)
95- cipher.init (Cipher .DECRYPT_MODE , getKey(), keySpec)
96- return cipher.doFinal(encryptedPairData?.second).toString(UTF_8 )
9799 } catch (ex: Exception ) {
98100 ex.printStackTrace()
99101 }
0 commit comments