我正在使用最低API版本10和目标17的Android应用程序。
我想使用KeyChain,但ICS之前不支持它。
有人可以针对此问题提出类似的建议或解决方案吗?
非常感谢
最佳答案
您可以使用SpongyCastle创建自己的KeyStore。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
KeyStore ks = null;
try {
ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null,null);
// Add certs or keys
ks.store(new FileOutputStream(new File(getFilesDir(),"out.bks")),"password".toCharArray());
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (CertificateException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
static {
Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
}
}
关于java - 在API级别14之前使用钥匙串(keychain),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17366490/