Java 如何在Cordova插件中从证书保存私钥
我需要保存并使用PrivateKey从cordova插件到另一个cordova插件。我的问题是,如何保存此密钥并在另一个cordova插件中使用,或在回调中发送此密钥,或将此密钥保存到PEM文件 这是Cordova插件的Java代码Java 如何在Cordova插件中从证书保存私钥,java,android,cordova,cordova-plugins,Java,Android,Cordova,Cordova Plugins,我需要保存并使用PrivateKey从cordova插件到另一个cordova插件。我的问题是,如何保存此密钥并在另一个cordova插件中使用,或在回调中发送此密钥,或将此密钥保存到PEM文件 这是Cordova插件的Java代码 public class CertificatePlugin extends CordovaPlugin implements KeyChainAliasCallback { private static String[] KEYTYPES = {"PKCS12
public class CertificatePlugin extends CordovaPlugin implements KeyChainAliasCallback {
private static String[] KEYTYPES = {"PKCS12"};
CallbackContext callbackContext = null;
@Override
public boolean execute(String action, JSONArray data, CallbackContext
callbackContext) throws JSONException {
this.callbackContext = callbackContext;
if ("selectCert".equals(action)) {
return selectCertificate();
}
return false;
}
private boolean selectCertificate() {
Activity activity = this.cordova.getActivity();
KeyChain.choosePrivateKeyAlias(activity, this, KEYTYPES, null,
null, -1, null);
return true;
}
private PrivateKey getPrivateKey(String alias) {
try {
PrivateKey pk = KeyChain.getPrivateKey(cordova.getActivity().getApplicationContext(), alias);
return pk;
} catch (KeyChainException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
public void alias(String alias) {
callbackContext.success(alias);
PrivateKey key = getPrivateKey (alias);
}
}你的头衔毫无意义。证书不包含私钥。您的标题没有意义。证书不包含私钥。