Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Cordova插件中从证书保存私钥_Java_Android_Cordova_Cordova Plugins - Fatal编程技术网

Java 如何在Cordova插件中从证书保存私钥

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

我需要保存并使用PrivateKey从cordova插件到另一个cordova插件。我的问题是,如何保存此密钥并在另一个cordova插件中使用,或在回调中发送此密钥,或将此密钥保存到PEM文件

这是Cordova插件的Java代码

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

}

你的头衔毫无意义。证书不包含私钥。您的标题没有意义。证书不包含私钥。