keystore.setKeyEntry(PRIVATESIGNKEYALIAS, p12privatekey,pkpass,certchain);
keystore.setKeyEntry(PRIVATESIGNKEYALIAS, p12privatekey,null,certchain);
   public void importKeysFromP12(PrivateKey p12privatekey, PublicKey p12publickey) throws Exception{        // lookup keystore passwords            InitialContext ictx = new InitialContext();      String keystorepass = (String) ictx.lookup("java:comp/env/keyStorePass");            if (keystorepass == null)        throw new IllegalArgumentException("Missing keyStorePass property.");              String privatekeypass = (String) ictx.lookup("java:comp/env/privateKeyPass");      char[] pkpass = null;      if ((privatekeypass).equals("null"))          pkpass = null;      else          pkpass = privatekeypass.toCharArray();                     // Currently only RSA keys are supported       KeyStore keystore = KeyStore.getInstance("PKCS12", "BC");       keystore.load(null,null);            // import sign keys.       int keysize = ((RSAPublicKey) p12publickey).getModulus().bitLength();       log.debug("KeySize="+keysize);       Certificate[] certchain = new Certificate[1];       certchain[0] = CertTools.genSelfCert("CN=dummy1", 1000, null, p12privatekey, p12publickey, true);       keystore.setKeyEntry(PRIVATESIGNKEYALIAS, p12privatekey,pkpass,certchain);                   // generate enc keys.         KeyPair enckeys = KeyTools.genKeys(keysize);       certchain[0] = CertTools.genSelfCert("CN=dummy2", 1000, null, enckeys.getPrivate(), enckeys.getPublic(), true);       this.encCert = certchain[0];       keystore.setKeyEntry(PRIVATEDECKEYALIAS,enckeys.getPrivate(),pkpass,certchain);                   java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();       keystore.store(baos, keystorepass.toCharArray());       data.put(KEYSTORE, new String(Base64.encode(baos.toByteArray())));       data.put(KEYSIZE, new Integer(keysize));       data.put(KEYALGORITHM, SoftCATokenInfo.KEYALGORITHM_RSA);       data.put(SIGNATUREALGORITHM, CATokenInfo.SIGALG_SHA_WITH_RSA);              // initalize CAToken       this.publicSignKey  = p12publickey;       this.privateSignKey = p12privatekey;              this.publicEncKey  = enckeys.getPublic();       this.privateDecKey = enckeys.getPrivate();   }   