A user run my application in Android N, he got the crash.I know Google deprecated Crypto provider in Android N,but what would be the best way to migrating old encrypted data.
Asked
Active
Viewed 8,192 times
2 Answers
21
For 8.0 and above you can refere here
For below 8.0 version you can go through following code.
You can use this provider replacing "Crypto" for SecureRandom, its working for me fine:
Use,
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", new CryptoProvider());
instead of,
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG","Crypto");
and your CryptoProvider class like as below,
import java.security.Provider;
/**
* Implementation of Provider for SecureRandom. The implementation supports the
* "SHA1PRNG" algorithm described in JavaTM Cryptography Architecture, API
* Specification & Reference
*/
public final class CryptoProvider extends Provider {
/**
* Creates a Provider and puts parameters
*/
public CryptoProvider() {
super("Crypto", 1.0, "HARMONY (SHA1 digest; SecureRandom; SHA1withDSA signature)");
put("SecureRandom.SHA1PRNG",
"org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl");
put("SecureRandom.SHA1PRNG ImplementedIn", "Software");
}
}

varotariya vajsi
- 3,965
- 37
- 39
-
I'm using this approach. However, my app gets crashed when I try to decrypt already encrypted data by old approach. Any solution to mitigate this issue? – Amrut Mar 13 '18 at 10:12
-
@Amrut I face same problem. Can you help me? did you find the solution of this – fahad_sust Oct 03 '18 at 20:43
-
2The Crypto provider is completely removed in Android P. We're getting below exception if we're using the above solution - java.security.NoSuchAlgorithmException: class configured for SecureRandom (provider: Crypto) cannot be found. – Amrut Oct 29 '18 at 08:39
-
2I have already facing this problem in Android P. Any solution to this issue? – Praveen Kumar Verma Dec 11 '18 at 08:08
-
Hello @PraveenKumarVerma please refer link i suggested into edited answer, it may help you for resolve issue of Android P. – varotariya vajsi Jan 30 '19 at 12:19
-
Can any one provide link to solve this issue which is compatible with both android 8 and 9 Pie? – Biswas Khayargoli Mar 05 '19 at 11:48
-
Hello, @BiswasKhayargoli have you checked https://stackoverflow.com/a/39002997/2897365 link? – varotariya vajsi Mar 05 '19 at 13:40
-
getting error : java.security.NoSuchAlgorithmException: class configured for SecureRandom (provider: Crypto) cannot be found. – Sagar Jethva Mar 18 '19 at 13:21
0
You can use this code for provider :
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").getProvider();

amin k
- 1
- 2