String privatekeypass = (String) ictx.lookup("java:comp/env/privateKeyPass"); char[] pkpass = null; if ((privatekeypass).equals("null")) pkpass = null; else pkpass = privatekeypass.toCharArray();
   public void generateKeys(CATokenInfo catokeninfo) 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       SoftCATokenInfo info = (SoftCATokenInfo) catokeninfo;              int keysize = info.getKeySize();         KeyStore keystore = KeyStore.getInstance("PKCS12", "BC");       keystore.load(null, null);              // generate sign keys.       KeyPair signkeys = KeyTools.genKeys(keysize);       // generate dummy certificate       Certificate[] certchain = new Certificate[1];       certchain[0] = CertTools.genSelfCert("CN=dummy", 36500, null, signkeys.getPrivate(), signkeys.getPublic(), true);              keystore.setKeyEntry(PRIVATESIGNKEYALIAS,signkeys.getPrivate(),pkpass, certchain);                           // generate enc keys.         KeyPair enckeys = KeyTools.genKeys(keysize);       // generate dummy certificate       certchain[0] = CertTools.genSelfCert("CN=dummy2", 36500, 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, info.getAlgorithm());       data.put(SIGNATUREALGORITHM, info.getSignatureAlgorithm());       // initalize CAToken       this.publicSignKey  = signkeys.getPublic();       this.privateSignKey = signkeys.getPrivate();                     this.publicEncKey  = enckeys.getPublic();       this.privateDecKey = enckeys.getPrivate();   }