[关闭]
@act262 2017-04-25T06:07:51.000000Z 字数 1605 阅读 1171

Android API 版本兼容问题

Android


Android App 中targetSdkVersion的作用

加密算法的变动:

  1. SecureRandom sr = SecureRandom.getInstance(SHA1, CRYPTO);
  1. public static SecureRandom getInstance(String algorithm, String provider)
  2. throws NoSuchAlgorithmException, NoSuchProviderException {
  3. try {
  4. Instance instance = GetInstance.getInstance("SecureRandom",
  5. SecureRandomSpi.class, algorithm, provider);
  6. return new SecureRandom((SecureRandomSpi) instance.impl,
  7. instance.provider, algorithm);
  8. } catch (NoSuchProviderException nspe) {
  9. if ("Crypto".equals(provider)) {
  10. System.logE(" ********** PLEASE READ ************ ");
  11. System.logE(" * ");
  12. System.logE(" * New versions of the Android SDK no longer support the Crypto provider.");
  13. System.logE(" * If your app was relying on setSeed() to derive keys from strings, you");
  14. System.logE(" * should switch to using SecretKeySpec to load raw key bytes directly OR");
  15. System.logE(" * use a real key derivation function (KDF). See advice here : ");
  16. System.logE(" * http://android-developers.blogspot.com/2016/06/security-crypto-provider-deprecated-in.html ");
  17. System.logE(" *********************************** ");
  18. // Target SDK <= 23 时使用旧版本的功能
  19. if (VMRuntime.getRuntime().getTargetSdkVersion()
  20. <= sdkTargetForCryptoProviderWorkaround) {
  21. System.logE(" Returning an instance of SecureRandom from the Crypto provider");
  22. System.logE(" as a temporary measure so that the apps targeting earlier SDKs");
  23. System.logE(" keep working. Please do not rely on the presence of the Crypto");
  24. System.logE(" provider in the codebase, as our plan is to delete it");
  25. System.logE(" completely in the future.");
  26. return getInstanceFromCryptoProvider(algorithm);
  27. }
  28. }
  29. throw nspe;
  30. }
  31. }

support library 变动

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注