if (! store.containsAlias(alias)) throw new SecurityException("Designated alias [" + alias + "] MUST be known to the key store in use");
  private void setupSigningParams() throws KeyStoreException, IOException,      NoSuchAlgorithmException, CertificateException,      UnsupportedCallbackException, UnrecoverableKeyException  {    log.entering("Main", "setupSigningParams");    if (ksURL == null || ksURL.trim().length() == 0)      {        String userHome = SystemProperties.getProperty("user.home");        if (userHome == null || userHome.trim().length() == 0)          throw new SecurityException("Option '-keystore' is not defined or"                                      + " is an empty string, and 'user.home'"                                      + " is unknown");        ksURL = "file:" + userHome.trim() + "/.keystore";      }    else      {        ksURL = ksURL.trim();        if (ksURL.indexOf(":") == -1)          ksURL = "file:" + ksURL;      }    if (ksType == null || ksType.trim().length() == 0)      ksType = KeyStore.getDefaultType();    else      ksType = ksType.trim();    store = KeyStore.getInstance(ksType);    if (ksPassword == null)      {        // ask the user to provide one        CallbackHandler handler = new ConsoleCallbackHandler();        PasswordCallback pcb = new PasswordCallback("Enter keystore password: ",                                                    false);        handler.handle(new Callback[] { pcb });        ksPasswordChars = pcb.getPassword();      }    else      ksPasswordChars = ksPassword.toCharArray();    URL url = new URL(ksURL);    InputStream stream = url.openStream();    store.load(stream, ksPasswordChars);    if (alias == null)      HelpPrinter.printHelpAndExit(HELP_PATH);    if (! store.containsAlias(alias))      throw new SecurityException("Designated alias [" + alias                                  + "] MUST be known to the key store in use");    if (! store.isKeyEntry(alias))      throw new SecurityException("Designated alias [" + alias                                  + "] MUST be an Alias of a Key Entry");    Key key;    if (password == null)      {        passwordChars = ksPasswordChars;        try          {            key = store.getKey(alias, passwordChars);          }        catch (UnrecoverableKeyException x)          {            // ask the user to provide one            CallbackHandler handler = new ConsoleCallbackHandler();            PasswordCallback pcb = new PasswordCallback("Enter key password for "                                                        + alias + ": ", false);            handler.handle(new Callback[] { pcb });            passwordChars = pcb.getPassword();            // take 2            key = store.getKey(alias, passwordChars);          }      }    else      {        passwordChars = password.toCharArray();        key = store.getKey(alias, passwordChars);      }    if (! (key instanceof PrivateKey))      throw new SecurityException("Key associated with " + alias                                  + " MUST be a private key");    signerPrivateKey = (PrivateKey) key;    signerCertificateChain = store.getCertificateChain(alias);    log.finest(String.valueOf(signerCertificateChain));    if (sigFileName == null)      sigFileName = alias;    sigFileName = sigFileName.toUpperCase(EN_US_LOCALE);    if (sigFileName.length() > 8)      sigFileName = sigFileName.substring(0, 8);    char[] chars = sigFileName.toCharArray();    for (int i = 0; i < chars.length; i++)      {        char c = chars[i];        if (! (Character.isLetter(c)            || Character.isDigit(c)            || c == '_'            || c == '-'))          chars[i] = '_';      }    sigFileName = new String(chars);    if (signedJarFileName == null)      signedJarFileName = jarFileName;    log.exiting("Main", "setupSigningParams");  }