Security “Crypto” provider deprecated in Android N

后端 未结 2 1150
攒了一身酷
攒了一身酷 2020-11-30 14:07

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

相关标签:
2条回答
  • 2020-11-30 14:59

    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");
    }
    }
    
    0 讨论(0)
  • 2020-11-30 15:02

    You can use this code for provider :

    SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").getProvider();
    
    0 讨论(0)
提交回复
热议问题