I need to encrypt password, but for Android 4.2 and below version, my solution doesn't work, The encrypted password is random. it's due to PRNG. So I saw this post :
https://android-developers.blogspot.com/2013/08/some-securerandom-thoughts.html
I implemented PRNGFixes, but it does not change...
How to solve this problem of randomly generated number ?
Code :
KeySpec spec = new PBEKeySpec(PASSWORD.toCharArray(), byteSalt, NB_ITER_RFC, SIZE_KEY);
SecretKey temp = factory.generateSecret(spec);
Cipher c = Cipher.getInstance(DES_EDE_PKCS5);
IvParameterSpec ivParam = new IvParameterSpec(bytesIv);
c.init(Cipher.ENCRYPT_MODE, temp, ivParam);
byte[] encrypted = c.doFinal(texteAChiffrer.getBytes("UTF-8"));
mdp = Base64.encodeToString(encrypted, Base64.DEFAULT);
OR :
PBEKeySpec pbeKeySpec = new PBEKeySpec(PASSWORD.toCharArray(), byteSalt, NB_ITER_RFC, SIZE_KEY);
byte[] key2 = PBEParametersGenerator.PKCS12PasswordToBytes(pbeKeySpec.getPassword());
SecretKey temp2 = factory.generateSecret(pbeKeySpec);
Cipher c2 = Cipher.getInstance(DES_EDE_PKCS5);
c2.init(Cipher.ENCRYPT_MODE, temp2, ivParam);
byte[] encrypted2 = c2.doFinal(texteAChiffrer.getBytes("UTF-8"));
mdp = Base64.encodeToString(encrypted2, Base64.DEFAULT);
This two solutions give the same results from Android 4.3 and latest versions (4.4 and 5.0)
Thank you for your help :)