我正在开发一个最低 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/