Example usage for java.security NoSuchAlgorithmException getMessage

List of usage examples for java.security NoSuchAlgorithmException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:gov.nist.toolkit.soap.axis2.AuthSSLProtocolSocketFactory.java

private SSLContext createSSLContext() throws IOException {
    try {//from  ww w . j a v a  2s. c  o  m
        KeyManager[] keymanagers = null;
        TrustManager[] trustmanagers = null;
        if (this.keystoreUrl != null) {
            KeyStore keystore = createKeyStore(this.keystoreUrl, this.keystorePassword);
            if (LOG.isDebugEnabled()) {
                Enumeration aliases = keystore.aliases();
                while (aliases.hasMoreElements()) {
                    String alias = (String) aliases.nextElement();
                    Certificate[] certs = keystore.getCertificateChain(alias);
                    if (certs != null) {
                        LOG.debug("Certificate chain '" + alias + "':");
                        for (int c = 0; c < certs.length; c++) {
                            if (certs[c] instanceof X509Certificate) {
                                X509Certificate cert = (X509Certificate) certs[c];
                                LOG.debug(" Certificate " + (c + 1) + ":");
                                LOG.debug("  Subject DN: " + cert.getSubjectDN());
                                LOG.debug("  Signature Algorithm: " + cert.getSigAlgName());
                                LOG.debug("  Valid from: " + cert.getNotBefore());
                                LOG.debug("  Valid until: " + cert.getNotAfter());
                                LOG.debug("  Issuer: " + cert.getIssuerDN());
                            }
                        }
                    }
                }
            }
            keymanagers = createKeyManagers(keystore, this.keystorePassword);
        }
        if (this.truststoreUrl != null) {
            KeyStore keystore = createKeyStore(this.truststoreUrl, this.truststorePassword);
            if (LOG.isDebugEnabled()) {
                Enumeration aliases = keystore.aliases();
                while (aliases.hasMoreElements()) {
                    String alias = (String) aliases.nextElement();
                    LOG.debug("Trusted certificate '" + alias + "':");
                    Certificate trustedcert = keystore.getCertificate(alias);
                    if (trustedcert != null && trustedcert instanceof X509Certificate) {
                        X509Certificate cert = (X509Certificate) trustedcert;
                        LOG.debug("  Subject DN: " + cert.getSubjectDN());
                        LOG.debug("  Signature Algorithm: " + cert.getSigAlgName());
                        LOG.debug("  Valid from: " + cert.getNotBefore());
                        LOG.debug("  Valid until: " + cert.getNotAfter());
                        LOG.debug("  Issuer: " + cert.getIssuerDN());
                    }
                }
            }
            trustmanagers = createTrustManagers(keystore);
        }
        SSLContext sslcontext = SSLContext.getInstance("SSL");
        sslcontext.init(keymanagers, trustmanagers, null);
        return sslcontext;
    } catch (NoSuchAlgorithmException e) {
        LOG.error(e.getMessage(), e);
        throw new IOException("Unsupported algorithm exception: " + e.getMessage());
    } catch (KeyStoreException e) {
        LOG.error(e.getMessage(), e);
        throw new IOException("Keystore exception: " + e.getMessage());
    } catch (GeneralSecurityException e) {
        LOG.error(e.getMessage(), e);
        throw new IOException("Key management exception: " + e.getMessage());
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
        throw new IOException("I/O error reading keystore/truststore file: " + e.getMessage());
    }
}

From source file:org.sciflex.plugins.synapse.esper.mediators.monitors.QueryActivityMonitor.java

/**
 * Method to obtain a hash of an input String.
 *
 * @param  input Input string//  w  w  w.  ja  va2s  . c  o  m
 * @return MD5 Hash of input.
 */
private String getHash(String input) {
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(input.getBytes());

        byte[] digest = md.digest();
        if (digest == null) {
            log.error("An error occured while acquiring Message Digest");
            return null;
        }
        StringBuffer sbuf = new StringBuffer();

        for (int i = 0; i < digest.length; i++) {
            String hex = Integer.toHexString(0xFF & digest[i]);

            if (hex.length() < 2) {
                sbuf.append("0");
            }
            sbuf.append(hex);
        }
        return sbuf.toString();
    } catch (NoSuchAlgorithmException e) {
        log.error("An error occured while acquiring Message Digest " + e.getMessage());
    }
    return null;
}

From source file:be.e_contract.eid.applet.service.impl.handler.IdentityDataMessageHandler.java

private void verifySignature(BeIDContextQualifier contextQualifier, String signAlgo, byte[] signatureData,
        X509Certificate certificate, HttpServletRequest request, byte[]... data) throws ServletException {
    Signature signature;//from ww w .  ja  v  a  2s .c o m
    try {
        signature = Signature.getInstance(signAlgo);
    } catch (NoSuchAlgorithmException e) {
        throw new ServletException("algo error: " + e.getMessage(), e);
    }
    PublicKey publicKey = certificate.getPublicKey();
    try {
        signature.initVerify(publicKey);
    } catch (InvalidKeyException e) {
        throw new ServletException("key error: " + e.getMessage(), e);
    }
    try {
        for (byte[] dataItem : data) {
            signature.update(dataItem);
        }
        boolean result = signature.verify(signatureData);
        if (false == result) {
            SecurityAuditEvent securityAuditEvent = new SecurityAuditEvent(Incident.DATA_INTEGRITY, certificate,
                    signatureData);
            this.securityAuditEvent.select(contextQualifier).fire(securityAuditEvent);
            throw new ServletException("signature incorrect");
        }
    } catch (SignatureException e) {
        SecurityAuditEvent securityAuditEvent = new SecurityAuditEvent(Incident.DATA_INTEGRITY, certificate,
                signatureData);
        this.securityAuditEvent.select(contextQualifier).fire(securityAuditEvent);
        throw new ServletException("signature error: " + e.getMessage(), e);
    }
}

From source file:com.CardPaymentGateway.GatewayAirtimeTopUp.java

public void run(String incomingMessage, String intid) {
    try {//  www.j  a va 2s  . c  o m
        strReceivedData = incomingMessage.split("#");
        strProcessingCode = strReceivedData[0];
        strAmount = strReceivedData[1];
        strTrack2Data = strReceivedData[2];
        strpin = strReceivedData[3];
        strPhoneNumber = strReceivedData[4];
        //strBillNumber=strReceivedData[5];
        strRefNo = strReceivedData[5];

        strDeviceid = strRefNo;

        if (strTrack2Data.contains("=")) {
            strCardInformation = strTrack2Data.split("=");
            strCardNumber = strCardInformation[0];
            //strExpiryDate = strCardInformation[1].substring(0, 4);
            int strlen = strCardNumber.length();
            if (strlen < 16) {
                strResponse = func.strPOSResponseHeader2(strDeviceid);
                strResponse += "--------------------------------" + "#";
                strResponse += "INVALID PAN #";
                //strResponse += "CARDNO: "+strCardNumber+ "#";
                //strResponse += "ExPiryDate: "+strExpiryDate+ "#";
                strResponse += func.strPOSResponseFooter(strDeviceid);
                func.SendPOSResponse(strResponse, intid);
                return;
            }
            strExpiryDate = strCardInformation[1].substring(0, 4);
            //String[] strTrack2Data1 = strCardInformation[1].split("\\?");
            //strField35 = strCardInformation[0] + "=" + strTrack2Data1[0];

        } else if (strTrack2Data.contains("D")) {

            strCardInformation = strTrack2Data.split("D");
            strCardNumber = strCardInformation[0];
            int strlen = strCardNumber.length();
            if (strlen < 16) {
                strResponse = func.strPOSResponseHeader2(strDeviceid);
                strResponse += "--------------------------------" + "#";
                strResponse += "INVALID PAN #";
                strResponse += func.strPOSResponseFooter(strDeviceid);
                func.SendPOSResponse(strResponse, strDeviceid);
                return;
            }
            strExpiryDate = strCardInformation[1].substring(0, 4);
            //String[] strTrack2Data1 = strCardInformation[1].split("\\?");
            //strField35 = strCardInformation[0] + "=" + strTrack2Data1[0];
        }

        //send transactionDetails from pos to PaymentGateway
        //Auth key Variables
        String uniqueKey = "!Eclectic%IsThe BomB%Limited!??hehehe";
        String phoneNumber = strPhoneNumber;

        //Transaction Details Json Data
        JSONObject object = new JSONObject();
        object.put("Amount", strAmount);
        object.put("CardNo", strCardNumber);
        object.put("Channel", "POS");
        object.put("Organization", "Eclectics");
        object.put("ExpiryDate", strExpiryDate);
        object.put("RefNo", strRefNo);
        object.put("PhoneNumber", strPhoneNumber);
        object.put("MessageType", "0200");
        object.put("Country", "Kenya");
        object.put("Pin", strpin);
        object.put("ProcessingCode", "000200");
        object.put("Biller", "Safaricom");
        object.put("PaymentMode", "Card");
        object.put("Account", strPhoneNumber);

        System.out.println("JSON DATA= " + object);

        String jsonString = object.toString().replaceAll("\"", "");

        String tobase64String = new BASE64Encoder().encode(jsonString.getBytes());//. Base64.getEncoder().encodeToString(jsonString.getBytes());
        //System.out.println("TO BASE64 STRING= "+tobase64String);

        //Auth key
        String authKeyString = uniqueKey + phoneNumber;
        //base64 of authKey
        String base64AuthString = new BASE64Encoder().encode(authKeyString.getBytes());// ++Base64.getEncoder().encodeToString(authKeyString.getBytes());
        //generate authKey sha512
        String sha512AuthKey = null;
        try {

            MessageDigest md = MessageDigest.getInstance("SHA-512");
            byte[] hash = md.digest(base64AuthString.getBytes());
            sha512AuthKey = convertToHex(hash);
        } catch (NoSuchAlgorithmException ex) {
            func.log("\nSEVERE GatewayAirtimeTopUp() :: " + ex.getMessage() + "\n" + func.StackTraceWriter(ex),
                    "ERROR");
        }
        System.out.println("SHA512 AUTH KEY= " + sha512AuthKey);
        //send request
        String response = authentication(tobase64String, sha512AuthKey);
        System.out.println(response);

        String noCurly = response.replaceAll("[{}]", "");
        String formatResponse[] = noCurly.split(",");

        strResponse = func.strPOSResponseHeader2(strDeviceid);
        strResponse += "--------------------------------" + "#";
        strResponse += "  AIRTIME TOP UP #";
        for (int i = 0; i < formatResponse.length; i++) {
            strResponse += formatResponse[i] + "#";
        }

        strResponse += func.strPOSResponseFooter(strDeviceid);
        func.SendPOSResponse(strResponse, strDeviceid);

    } catch (Exception ex) {
        func.log("\nSEVERE GatewayAirtimeTopUp() :: " + ex.getMessage() + "\n" + func.StackTraceWriter(ex),
                "ERROR");
    }
}

From source file:org.intermine.webservice.server.JWTVerifier.java

private boolean verifySignature(PublicKey key, String algorithm, String signed, byte[] toVerify)
        throws VerificationError {
    Signature signature;// w  ww.j a  v a 2  s  . c  om
    try {
        signature = Signature.getInstance(algorithm);
    } catch (NoSuchAlgorithmException e) {
        throw new VerificationError(e.getMessage());
    }
    try {
        signature.initVerify(key);
    } catch (InvalidKeyException e) {
        throw new VerificationError("Key is invalid. " + e.getMessage());
    }

    try {
        signature.update(signed.getBytes());
    } catch (SignatureException e) {
        throw new VerificationError("Error creating signature: " + e.getMessage());
    }

    try {
        return signature.verify(toVerify);
    } catch (SignatureException e) {
        throw new VerificationError("Error during verification: " + e.getMessage());
    }
}

From source file:org.openhealthtools.openatna.net.SecureSocketFactory.java

private SSLContext createSSLContext() throws IOException {
    try {/*from  w  ww  .j  a  v  a2 s . co  m*/
        log.debug("Attempting to create ssl context.");
        KeyManager[] keymanagers = null;
        TrustManager[] trustmanagers = null;
        if (this.keystoreUrl == null) {
            throw new IOException("Cannot create SSL context without keystore");
        }
        if (this.keystoreUrl != null) {
            KeyStore keystore = ConnectionCertificateHandler.createKeyStore(this.keystoreUrl,
                    this.keystorePassword);
            if (log.isDebugEnabled()) {
                ConnectionCertificateHandler.printKeyCertificates(keystore);
            }
            keymanagers = ConnectionCertificateHandler.createKeyManagers(keystore, this.keystorePassword);
        }
        if (this.truststoreUrl != null) {
            KeyStore keystore = ConnectionCertificateHandler.createKeyStore(this.truststoreUrl,
                    this.truststorePassword);
            if (log.isDebugEnabled()) {
                ConnectionCertificateHandler.printTrustCerts(keystore);
            }
            trustmanagers = ConnectionCertificateHandler.createTrustManagers(keystore, this.scd);
        }
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(keymanagers, trustmanagers, null);
        return sslcontext;
    } catch (NoSuchAlgorithmException e) {
        log.error("NSA: " + e.getMessage(), e);
        throw new IOException("Unsupported algorithm exception: " + e.getMessage());
    } catch (KeyStoreException e) {
        log.error("Key Store: " + e.getMessage(), e);
        throw new IOException("Keystore exception: " + e.getMessage());
    } catch (GeneralSecurityException e) {
        log.error("General: " + e.getMessage(), e);
        throw new IOException("Key management exception: " + e.getMessage());
    } catch (IOException e) {
        log.error("I/O exception: " + e.getMessage(), e);
        throw new IOException("I/O error reading keystore/truststore file: " + e.getMessage());
    }
}

From source file:com.sshtools.j2ssh.transport.kex.DhGroup1Sha1.java

/**
 *
 *
 * @throws IOException/*from  w  w w  .  j  a v a2 s.  c  o m*/
 * @throws AlgorithmNotSupportedException
 */
protected void onInit() throws IOException {

    try {
        dhKeyPairGen = KeyPairGenerator.getInstance("DH");
        dhKeyAgreement = KeyAgreement.getInstance("DH");
    } catch (NoSuchAlgorithmException ex) {
        throw new AlgorithmNotSupportedException(ex.getMessage());
    }
}

From source file:org.nuxeo.launcher.TestNuxeoLauncher.java

/**
 * NXP-19071: avoid confusion with the command parameters when passing an argument to an option, or when calling
 * without argument an option which accepts optional arguments.
 *
 * @throws Exception/*from  ww  w.java  2 s.com*/
 * @since 8.2
 */
@Test
public void testParamSeparator() throws Exception {
    // failing syntax: "value1" is parsed as an argument to "--encrypt" option
    NuxeoLauncher launcher = NuxeoLauncher
            .createLauncher(new String[] { "encrypt", "--encrypt", "value1", "value2" });
    assertTrue(launcher.commandIs("encrypt"));
    assertTrue(launcher.cmdLine.hasOption(NuxeoLauncher.OPTION_ENCRYPT));
    assertEquals("value1", launcher.cmdLine.getOptionValue(NuxeoLauncher.OPTION_ENCRYPT));
    assertArrayEquals(new String[] { "value2" }, launcher.params);
    try {
        launcher.encrypt();
        fail("Expected 'java.security.NoSuchAlgorithmException: Cannot find any provider supporting value1'");
    } catch (NoSuchAlgorithmException e) {
        assertEquals("Cannot find any provider supporting value1", e.getMessage());
    }

    // working syntax: "value1" is a parsed as a parameter to "encrypt" command
    // 1) option without argument placed at the end
    launcher = NuxeoLauncher.createLauncher(new String[] { "encrypt", "value1", "value2", "--encrypt" });
    checkParsing(launcher);
    // 2) option with an argument
    launcher = NuxeoLauncher.createLauncher(
            new String[] { "encrypt", "--encrypt", "AES/ECB/PKCS5Padding", "value1", "value2" });
    checkParsing(launcher);
    // 3) option without argument separated with "--"
    launcher = NuxeoLauncher.createLauncher(new String[] { "encrypt", "--encrypt", "--", "value1", "value2" });
    checkParsing(launcher);

    // Check specific case of the "--set" option
    launcher = NuxeoLauncher.createLauncher(new String[] { "config", "--set", "someTemplate", "someKey" });
    assertTrue(launcher.commandIs("config"));
    assertTrue(launcher.cmdLine.hasOption(NuxeoLauncher.OPTION_SET));
    assertEquals("someTemplate", launcher.cmdLine.getOptionValue(NuxeoLauncher.OPTION_SET));
    assertArrayEquals(new String[] { "someKey" }, launcher.params);

    launcher = NuxeoLauncher.createLauncher(new String[] { "config", "--set", "--", "someKey" });
    assertTrue(launcher.commandIs("config"));
    assertTrue(launcher.cmdLine.hasOption(NuxeoLauncher.OPTION_SET));
    assertEquals(null, launcher.cmdLine.getOptionValue(NuxeoLauncher.OPTION_SET));
    assertArrayEquals(new String[] { "someKey" }, launcher.params);

    launcher = NuxeoLauncher.createLauncher(new String[] { "config", "someKey", "--set" });
    assertTrue(launcher.commandIs("config"));
    assertTrue(launcher.cmdLine.hasOption(NuxeoLauncher.OPTION_SET));
    assertEquals(null, launcher.cmdLine.getOptionValue(NuxeoLauncher.OPTION_SET));
    assertArrayEquals(new String[] { "someKey" }, launcher.params);
}

From source file:com.utest.webservice.client.rest.AuthSSLProtocolSocketFactory.java

@SuppressWarnings("unchecked")
private SSLContext createSSLContext() {
    try {/* w  w w  . j a v  a 2 s  .c  o  m*/
        KeyManager[] keymanagers = null;
        TrustManager[] trustmanagers = null;
        if (this.keystoreUrl != null) {
            KeyStore keystore = createKeyStore(this.keystoreUrl, this.keystorePassword);
            if (true) {
                Enumeration aliases = keystore.aliases();
                while (aliases.hasMoreElements()) {
                    String alias = (String) aliases.nextElement();
                    Certificate[] certs = keystore.getCertificateChain(alias);
                    if (certs != null) {
                        System.out.println("Certificate chain '" + alias + "':");
                        for (int c = 0; c < certs.length; c++) {
                            if (certs[c] instanceof X509Certificate) {
                                X509Certificate cert = (X509Certificate) certs[c];
                                System.out.println(" Certificate " + (c + 1) + ":");
                                System.out.println("  Subject DN: " + cert.getSubjectDN());
                                System.out.println("  Signature Algorithm: " + cert.getSigAlgName());
                                System.out.println("  Valid from: " + cert.getNotBefore());
                                System.out.println("  Valid until: " + cert.getNotAfter());
                                System.out.println("  Issuer: " + cert.getIssuerDN());
                            }
                        }
                    }
                }
            }
            keymanagers = createKeyManagers(keystore, this.keystorePassword);
        }
        if (this.truststoreUrl != null) {
            KeyStore keystore = createKeyStore(this.truststoreUrl, this.truststorePassword);
            if (true) {
                Enumeration aliases = keystore.aliases();
                while (aliases.hasMoreElements()) {
                    String alias = (String) aliases.nextElement();
                    System.out.println("Trusted certificate '" + alias + "':");
                    Certificate trustedcert = keystore.getCertificate(alias);
                    if (trustedcert != null && trustedcert instanceof X509Certificate) {
                        X509Certificate cert = (X509Certificate) trustedcert;
                        System.out.println("  Subject DN: " + cert.getSubjectDN());
                        System.out.println("  Signature Algorithm: " + cert.getSigAlgName());
                        System.out.println("  Valid from: " + cert.getNotBefore());
                        System.out.println("  Valid until: " + cert.getNotAfter());
                        System.out.println("  Issuer: " + cert.getIssuerDN());
                    }
                }
            }
            trustmanagers = createTrustManagers(keystore);
        }
        SSLContext sslcontext = SSLContext.getInstance("SSL");
        sslcontext.init(keymanagers, trustmanagers, null);
        return sslcontext;
    } catch (NoSuchAlgorithmException e) {
        System.out.println(e.getMessage());
        throw new AuthSSLInitializationError("Unsupported algorithm exception: " + e.getMessage());
    } catch (KeyStoreException e) {
        System.out.println(e.getMessage());
        throw new AuthSSLInitializationError("Keystore exception: " + e.getMessage());
    } catch (GeneralSecurityException e) {
        System.out.println(e.getMessage());
        throw new AuthSSLInitializationError("Key management exception: " + e.getMessage());
    } catch (IOException e) {
        System.out.println(e.getMessage());
        throw new AuthSSLInitializationError("I/O error reading keystore/truststore file: " + e.getMessage());
    }
}

From source file:edu.vt.middleware.crypt.CryptProvider.java

/**
 * <p>This finds a <code>KeyFactory</code> using the known providers and the
 * supplied algorithm parameter.</p>
 *
 * @param  algorithm  <code>String</code> name
 *
 * @return  <code>KeyFactory</code>
 *
 * @throws  CryptException  if the algorithm is not available from any
 * provider or if the provider is not available in the environment
 *///from w  w  w  . j ava2 s.c o m
public static KeyFactory getKeyFactory(final String algorithm) throws CryptException {
    final Log logger = LogFactory.getLog(CryptProvider.class);
    KeyFactory kf = null;
    for (int i = 0; i < providers.length; i++) {
        try {
            kf = KeyFactory.getInstance(algorithm, providers[i]);
        } catch (NoSuchAlgorithmException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find algorithm " + algorithm + " in " + providers[i]);
            }
        } catch (NoSuchProviderException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find provider " + providers[i]);
            }
        } finally {
            if (kf != null) {
                break;
            }
        }
    }
    if (kf == null) {
        try {
            kf = KeyFactory.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find algorithm " + algorithm);
            }
            throw new CryptException(e.getMessage());
        }
    }
    return kf;
}