problem with decrypting String cipher
Hi, I am generating cipher for my token and CVV then saving both in sharedPref. Next time for any token am generating again cipher. Checking if that cipher exists in sharedPref. If it exists I am reading the CVV cipher against this token cipher. Later am trying to decrypt this CVV cipher. But it seems everytime I try to generate cipher for same String, am getting different cipher. Can I have the same cipher for given String?
Back from vacations!
Hi, I'm not sure if I follow. Maybe a little code example should help me understand.
Let me see if I got your question: you are encrypting twice the same plain data, and then you get different outputs each time, right?
That is correct. The resulting cipher data is result (besides the algorithm used of course), the key and the initialization vector (IV). The IV is randomly generated for each encryption. That is important because an attacker cannot infer any information about the key by trying different specially crafted data. Failing to use strong random IV's is a vulnerability.
https://en.wikipedia.org/wiki/Initialization_vector
I'm assuming that the encryption key is the same. If you are using the provided SharedPrefsKeyChain it should be the case as it generates a random key the first time, and from then on, uses it.