Example usage for java.security ProviderException getMessage

List of usage examples for java.security ProviderException getMessage

Introduction

In this page you can find the example usage for java.security ProviderException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:es.mityc.firmaJava.libreria.pkcs7.ValidaTarjeta.java

private void validarTarjeta() {
    Runnable doWorkRunnable = new Runnable() {
        public void run() {
            ConexionTarjeta c = ConexionTarjeta.getInstance();
            try {
                ks = c.conectar(jPinPasswordField.getPassword(), jLibreriaTextField.getText());
                ValidaTarjeta.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                dispose();//from  w w  w  .jav  a 2 s. co m
            } catch (ProviderException e1) {
                JOptionPane.showMessageDialog(jPanel, e1.getMessage(),
                        I18n.getResource(LIBRERIAXADES_VALIDARTARJETA_TEXTO_23), JOptionPane.ERROR_MESSAGE);
            } catch (PKCS11Exception e1) {
                String mensajeError = mensajeErrorConexion(String.valueOf(e1.getErrorCode()));
                JOptionPane.showMessageDialog(jPanel, mensajeError,
                        I18n.getResource(LIBRERIAXADES_VALIDARTARJETA_TEXTO_23), JOptionPane.ERROR_MESSAGE);
            }
            ValidaTarjeta.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    };

    ValidaTarjeta.this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    SwingUtilities.invokeLater(doWorkRunnable);
}

From source file:org.signserver.server.cryptotokens.CryptoTokenHelper.java

public static TokenSearchResults searchTokenEntries(final KeyStore keyStore, final int startIndex,
        final int max, final QueryCriteria qc, final boolean includeData)
        throws CryptoTokenOfflineException, QueryException {
    final TokenSearchResults result;
    try {//from www  .ja  v  a2  s .c  om
        final ArrayList<TokenEntry> tokenEntries = new ArrayList<TokenEntry>();
        final Enumeration<String> e = keyStore.aliases(); // We assume the order is the same for every call unless entries has been added or removed

        final long maxIndex = (long) startIndex + max;
        for (int i = 0; i < maxIndex && e.hasMoreElements();) {
            final String keyAlias = e.nextElement();

            final String type;
            if (keyStore.entryInstanceOf(keyAlias, KeyStore.PrivateKeyEntry.class)) {
                type = TokenEntry.TYPE_PRIVATEKEY_ENTRY;
            } else if (keyStore.entryInstanceOf(keyAlias, KeyStore.SecretKeyEntry.class)) {
                type = TokenEntry.TYPE_SECRETKEY_ENTRY;
            } else if (keyStore.entryInstanceOf(keyAlias, KeyStore.TrustedCertificateEntry.class)) {
                type = TokenEntry.TYPE_TRUSTED_ENTRY;
            } else {
                type = null;
            }

            TokenEntry entry = new TokenEntry(keyAlias, type);

            if (shouldBeIncluded(entry, qc)) {
                if (i < startIndex) {
                    i++;
                    continue;
                }

                if (LOG.isDebugEnabled()) {
                    LOG.debug("checking keyAlias: " + keyAlias);
                }

                // Add additional data
                if (includeData) {
                    Map<String, String> info = new HashMap<String, String>();
                    try {
                        Date creationDate = keyStore.getCreationDate(keyAlias);
                        entry.setCreationDate(creationDate);
                    } catch (ProviderException ex) {
                    } // NOPMD: We ignore if it is not supported

                    if (TokenEntry.TYPE_PRIVATEKEY_ENTRY.equals(type)) {
                        final Certificate[] chain = keyStore.getCertificateChain(keyAlias);
                        if (chain.length > 0) {
                            info.put(INFO_KEY_ALGORITHM,
                                    AlgorithmTools.getKeyAlgorithm(chain[0].getPublicKey()));
                            info.put(INFO_KEY_SPECIFICATION,
                                    AlgorithmTools.getKeySpecification(chain[0].getPublicKey()));
                        }
                        try {
                            entry.setParsedChain(chain);
                        } catch (CertificateEncodingException ex) {
                            info.put("Error", ex.getMessage());
                            LOG.error("Certificate could not be encoded for alias: " + keyAlias, ex);
                        }
                    } else if (TokenEntry.TYPE_TRUSTED_ENTRY.equals(type)) {
                        Certificate certificate = keyStore.getCertificate(keyAlias);
                        try {
                            entry.setParsedTrustedCertificate(certificate);
                        } catch (CertificateEncodingException ex) {
                            info.put("Error", ex.getMessage());
                            LOG.error("Certificate could not be encoded for alias: " + keyAlias, ex);
                        }
                    } else if (TokenEntry.TYPE_SECRETKEY_ENTRY.equals(type)) {
                        try {
                            KeyStore.Entry entry1 = keyStore.getEntry(keyAlias, null);
                            SecretKey secretKey = ((KeyStore.SecretKeyEntry) entry1).getSecretKey();

                            info.put(INFO_KEY_ALGORITHM, secretKey.getAlgorithm());
                            //info.put(INFO_KEY_SPECIFICATION, AlgorithmTools.getKeySpecification(chain[0].getPublicKey())); // TODO: Key specification support for secret keys
                        } catch (NoSuchAlgorithmException ex) {
                            info.put("Error", ex.getMessage());
                            LOG.error("Unable to get secret key for alias: " + keyAlias, ex);
                        } catch (UnrecoverableEntryException ex) {
                            info.put("Error", ex.getMessage());
                            LOG.error("Unable to get secret key for alias: " + keyAlias, ex);
                        }
                    }
                    entry.setInfo(info);
                }
                tokenEntries.add(entry);

                // Increase index
                i++;
            }
        }
        result = new TokenSearchResults(tokenEntries, e.hasMoreElements());
    } catch (KeyStoreException ex) {
        throw new CryptoTokenOfflineException(ex);
    }
    return result;
}