Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

Security "Crypto" provider deprecated in Android N

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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");
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...