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:securitytools.nessus.NessusClient.java

public NessusClient(HttpHost targetHost, ClientConfiguration clientConfiguration) {
    this.target = targetHost;

    context = HttpClientContext.create();

    try {//from   w  w w.j  a v  a 2s.  c o m
        client = HttpClientFactory.build(clientConfiguration);
    } catch (NoSuchAlgorithmException nsae) {
        throw new NessusClientException(nsae.getMessage(), nsae);
    }
}

From source file:com.adaptris.core.services.metadata.PayloadHashingService.java

@Override
protected void initService() throws CoreException {
    if (getHashAlgorithm() == null || "".equals(getHashAlgorithm())) {
        throw new CoreException("hash-algorithm is null");
    }/*from  w  w  w.ja v  a 2s  .c  o  m*/
    if (getMetadataKey() == null || "".equals(getMetadataKey())) {
        throw new CoreException("metadata-key is null");
    }
    try {
        MessageDigest d = MessageDigest.getInstance(getHashAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        throw new CoreException(e.getMessage(), e);
    }
}

From source file:ch.cyberduck.core.io.AbstractChecksumCompute.java

protected byte[] digest(final String algorithm, final InputStream in) throws ChecksumException {
    final MessageDigest md;
    try {// w  w w  .  ja  v  a  2 s .c  om
        md = MessageDigest.getInstance(algorithm);
    } catch (NoSuchAlgorithmException e) {
        throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e.getMessage(),
                e);
    }
    try {
        byte[] buffer = new byte[16384];
        int bytesRead;
        while ((bytesRead = in.read(buffer, 0, buffer.length)) != -1) {
            md.update(buffer, 0, bytesRead);
        }
    } catch (IOException e) {
        throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e.getMessage(),
                e);
    } finally {
        IOUtils.closeQuietly(in);
    }
    return md.digest();
}

From source file:org.opendatakit.common.android.utilities.ODKFileUtils.java

public static String getNakedMd5Hash(String appName, File file) {
    try {/*  ww w .  j  a  va  2s.  co m*/
        // CTS (6/15/2010) : stream file through digest instead of handing
        // it the byte[]
        MessageDigest md = MessageDigest.getInstance("MD5");
        int chunkSize = 8192;

        byte[] chunk = new byte[chunkSize];

        // Get the size of the file
        long lLength = file.length();

        if (lLength > Integer.MAX_VALUE) {
            WebLogger.getLogger(appName).e(t, "File " + file.getName() + "is too large");
            return null;
        }

        int length = (int) lLength;

        InputStream is = null;
        is = new FileInputStream(file);

        int l = 0;
        for (l = 0; l + chunkSize < length; l += chunkSize) {
            is.read(chunk, 0, chunkSize);
            md.update(chunk, 0, chunkSize);
        }

        int remaining = length - l;
        if (remaining > 0) {
            is.read(chunk, 0, remaining);
            md.update(chunk, 0, remaining);
        }
        byte[] messageDigest = md.digest();

        BigInteger number = new BigInteger(1, messageDigest);
        String md5 = number.toString(16);
        while (md5.length() < 32)
            md5 = "0" + md5;
        is.close();
        return md5;

    } catch (NoSuchAlgorithmException e) {
        WebLogger.getLogger(appName).e("MD5", e.getMessage());
        return null;

    } catch (FileNotFoundException e) {
        WebLogger.getLogger(appName).e("No Cache File", e.getMessage());
        return null;
    } catch (IOException e) {
        WebLogger.getLogger(appName).e("Problem reading from file", e.getMessage());
        return null;
    }

}

From source file:org.opendatakit.common.android.utilities.ODKFileUtils.java

public static String getNakedMd5Hash(String appName, String contents) {
    try {/*from w ww . j av  a 2s.co  m*/
        // CTS (6/15/2010) : stream file through digest instead of handing
        // it the byte[]
        MessageDigest md = MessageDigest.getInstance("MD5");
        int chunkSize = 256;

        byte[] chunk = new byte[chunkSize];

        // Get the size of the file
        long lLength = contents.length();

        if (lLength > Integer.MAX_VALUE) {
            WebLogger.getLogger(appName).e(t, "Contents is too large");
            return null;
        }

        int length = (int) lLength;

        InputStream is = null;
        is = new ByteArrayInputStream(contents.getBytes(CharEncoding.UTF_8));

        int l = 0;
        for (l = 0; l + chunkSize < length; l += chunkSize) {
            is.read(chunk, 0, chunkSize);
            md.update(chunk, 0, chunkSize);
        }

        int remaining = length - l;
        if (remaining > 0) {
            is.read(chunk, 0, remaining);
            md.update(chunk, 0, remaining);
        }
        byte[] messageDigest = md.digest();

        BigInteger number = new BigInteger(1, messageDigest);
        String md5 = number.toString(16);
        while (md5.length() < 32)
            md5 = "0" + md5;
        is.close();
        return md5;

    } catch (NoSuchAlgorithmException e) {
        WebLogger.getLogger(appName).e("MD5", e.getMessage());
        return null;

    } catch (FileNotFoundException e) {
        WebLogger.getLogger(appName).e("No Cache File", e.getMessage());
        return null;
    } catch (IOException e) {
        WebLogger.getLogger(appName).e("Problem reading from file", e.getMessage());
        return null;
    }

}

From source file:com.linuxbox.enkive.message.AbstractBaseContentData.java

protected void calculateHash() {
    // if there's no data then there's no hash
    if (data == null) {
        clearHash();/* w ww.j  a va2  s . co  m*/
        return;
    }

    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance(HASH_ALGORITHM);
    } catch (NoSuchAlgorithmException e) {
        throw new EnkiveRuntimeException(e.getMessage());
    }

    md.update(data);

    hashBytes = md.digest();
    hashString = new String((new Hex()).encode(hashBytes));
}

From source file:org.rhq.enterprise.server.util.security.UntrustedSSLProtocolSocketFactory.java

public UntrustedSSLProtocolSocketFactory() {
    super();/* w ww  .  ja va  2 s. c om*/

    try {
        BogusTrustManager trustMan;
        SSLContext tlsContext;

        trustMan = new BogusTrustManager();
        tlsContext = SSLContext.getInstance("TLS");
        tlsContext.init(null, new X509TrustManager[] { trustMan }, null);
        this.factory = tlsContext.getSocketFactory();
    } catch (NoSuchAlgorithmException exc) {
        throw new IllegalStateException("Unable to get SSL context: " + exc.getMessage());
    } catch (KeyManagementException exc) {
        throw new IllegalStateException("Unable to initialize ctx with BogusTrustManager: " + exc.getMessage());
    }
}

From source file:org.warcbase.index.IndexerMapper.java

@Override
public void configure(JobConf job) {
    try {/*w w w .j a v a 2  s. co m*/
        LOG.info("Configuring WARCIndexer.");
        Config config = ConfigFactory.parseString(job.get(IndexerRunner.CONFIG_PROPERTIES));
        this.indexer = new WARCIndexer(config);

        numShards = job.getInt(NUM_SHARDS, 10);
        LOG.info("Number of shards: " + numShards);

        mapTaskId = job.get("mapred.task.id");
        inputFile = job.get("map.input.file");
        LOG.info("Got task.id " + mapTaskId + " and input.file " + inputFile);
    } catch (NoSuchAlgorithmException e) {
        LOG.error("IndexerMapper.configure(): " + e.getMessage());
    }
}

From source file:burstcoin.address.generator.core.GenerateWorkActor.java

/**
 * Gets message digest./*from w w  w.  jav a 2 s  . co  m*/
 *
 * @return the message digest
 */
public MessageDigest getMessageDigest() {
    try {
        return MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:be.apsu.extremon.probes.ocsp.OCSPProbe.java

public OCSPProbe() {
    CertificateFactory certificateFactory = null;

    try {//w  w  w .j ava  2s  .c om
        certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException cex) {
        log("Don't Have Crypto Libs:" + cex.getMessage());
        System.exit(1);
    }

    try {
        certificate = (X509Certificate) certificateFactory
                .generateCertificate(new ByteArrayInputStream(Base64.decodeBase64(confStr("certificate"))));
        trustAnchorCert = (X509Certificate) certificateFactory
                .generateCertificate(new ByteArrayInputStream(Base64.decodeBase64(confStr("trustanchor"))));
    } catch (CertificateException cex) {
        log("certificate and trustanchor required in config:" + cex.getMessage());
        System.exit(2);
    }

    this.delay = confInt("delay", DEFAULT_DELAY);

    try {
        List<X509Certificate> certs = new ArrayList<X509Certificate>();
        certs.add(this.certificate);
        this.certificatePath = (CertPath) certificateFactory.generateCertPath(certs);

        TrustAnchor trustAnchor = new TrustAnchor(this.trustAnchorCert, null);
        Set<TrustAnchor> trustedCertsSet = new HashSet<TrustAnchor>();
        trustedCertsSet.add(trustAnchor);

        Set<X509Certificate> certSet = new HashSet<X509Certificate>();
        certSet.add(this.trustAnchorCert);
        CertStoreParameters storeParams = new CollectionCertStoreParameters(certSet);
        CertStore store = CertStore.getInstance("Collection", storeParams);

        pkixParams = new PKIXParameters(trustedCertsSet);
        pkixParams.addCertStore(store);

        Security.setProperty("ocsp.enable", "true");
        Security.setProperty("ocsp.responderURL", confStr("url"));
        Security.setProperty("ocsp.responderCertSubjectName",
                this.trustAnchorCert.getSubjectX500Principal().getName());

        this.certificatePathValidator = CertPathValidator.getInstance("PKIX");
    } catch (InvalidAlgorithmParameterException iaex) {
        log("Invalid Algorithm Parameter:" + iaex.getMessage());
        System.exit(3);
    } catch (CertificateException cex) {
        log("Certificate Exception:" + cex.getMessage());
        System.exit(4);
    } catch (NoSuchAlgorithmException nsaex) {
        log("No Such Algorithm:" + nsaex.getMessage());
        System.exit(5);
    } catch (Exception ex) {
        log(ex.getMessage());
        System.exit(6);
    }

    start();
    log("Initialized");
}