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:opennlp.tools.textsimilarity.TextProcessor.java

public static String generateFingerPrintForHistogram(String s) throws Exception {

    Hashtable tokenHash = new Hashtable();
    // ArrayList tokens = TextProcessor.tokenizeWithPunctuation(s);
    ArrayList tokens = TextProcessor.fastTokenize(s, true);

    for (Object t : tokens) {
        String tokenLower = ((String) (t)).toLowerCase();

        if (tokenLower == "<punc>") {
            continue;
        }/*  w ww.  jav a2 s  . c o m*/
        if (tokenLower == "close_a") {
            continue;
        }
        if (tokenLower == "open_a") {
            continue;
        }
        String stemmedToken = TextProcessor.stemTerm(tokenLower);

        if (tokenHash.containsKey(stemmedToken)) {
            int freq = ((Integer) tokenHash.get(stemmedToken)).intValue();
            freq++;
            tokenHash.put(stemmedToken, new Integer(freq));
        } else {
            tokenHash.put(stemmedToken, new Integer(1));
        }
    }

    // now we have histogram, lets write it out
    String hashString = "";
    Enumeration en = tokenHash.keys();
    while (en.hasMoreElements()) {
        String t = (String) en.nextElement();
        int freq = (Integer) tokenHash.get(t);
        hashString += t + freq;
    }

    // log.info(hashString);
    String hash = "";

    if (hashString.length() > 0) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA"); // step 2
        } catch (NoSuchAlgorithmException e) {
            LOG.severe("NoSuchAlgorithmException " + e);
            throw new Exception(e.getMessage());
        }
        try {
            md.update(hashString.getBytes("UTF-8")); // step 3
        } catch (UnsupportedEncodingException e) {
            LOG.severe("UnsupportedEncodingException " + e);
            throw new Exception(e.getMessage());
        }
        byte raw[] = md.digest();
        hash = null; // (new BASE64Encoder()).encode(raw);
    }
    return hash;
}

From source file:org.apache.sling.cassandra.resource.provider.mapper.DefaultCassandraMapperImpl.java

public String getCQL(String columnFamilySelector, String path) throws CassandraMapperException {
    MessageDigest md = null;/*from w w w .  j a  v a2 s  .c o m*/
    try {
        md = MessageDigest.getInstance("SHA1");
        String rowID = new String(Base64.encodeBase64(md.digest(path.getBytes("UTF-8"))));
        return "select * from " + columnFamilySelector + " where KEY = '" + rowID + "'";
    } catch (NoSuchAlgorithmException e) {
        throw new CassandraMapperException(e.getMessage());
    } catch (UnsupportedEncodingException e) {
        throw new CassandraMapperException(e.getMessage());
    }
}

From source file:org.apache.oodt.product.handlers.ofsn.MD5GetHandler.java

public MD5GetHandler() throws InstantiationException {
    try {/* w w  w  .j  a  v  a 2  s . c  o  m*/
        this.md = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        LOG.log(Level.SEVERE, e.getMessage());
        throw new InstantiationException(e.getMessage());
    }
}

From source file:org.craftercms.social.util.support.security.crypto.SimpleDesCipher.java

public SimpleDesCipher(String base64Key) {
    try {//from   ww w .j  ava2 s .  c o m
        cipher = Cipher.getInstance("DESede");
    } catch (NoSuchAlgorithmException e1) {
        log.error(e1.getMessage(), e1);
    } catch (NoSuchPaddingException e) {
        log.error(e.getMessage(), e);
    }

    byte[] raw = Base64.decodeBase64(base64Key);

    DESedeKeySpec keyspec;
    try {
        keyspec = new DESedeKeySpec(raw);

        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
        skey = keyfactory.generateSecret(keyspec);
    } catch (InvalidKeyException e) {
        log.error(e.getMessage(), e);
    } catch (NoSuchAlgorithmException e) {
        log.error(e.getMessage(), e);
    } catch (InvalidKeySpecException e) {
        log.error(e.getMessage(), e);
    }
}

From source file:graphene.util.crypto.PasswordHashTest.java

@Test
public void testSalt() {
    final PasswordHash p = new PasswordHash();

    try {/*from  w w  w . j a  v  a  2s  . co  m*/
        // System.out.println(p.createHash("password"));
        final byte[] s = p.pbkdf2("password".toCharArray(), "salt".getBytes(), PasswordHash.PBKDF2_ITERATIONS,
                PasswordHash.HASH_BYTE_SIZE);
        System.out.println(s);
        System.out.println("base64 bytes: " + Base64.encodeBase64String("salt".getBytes()));
        System.out.println("hex of \"salt\".getBytes(): " + p.toHex("salt".getBytes()));
    } catch (final NoSuchAlgorithmException e) {
        logger.error(e.getMessage());
    } catch (final InvalidKeySpecException e) {
        logger.error(e.getMessage());
    }
}

From source file:org.apache.wookie.util.HashGenerator.java

public synchronized String generateEncryption(String plaintext) throws SystemUnavailableException {

    MessageDigest md = null;//from   w  ww  .j  a v  a 2  s . co  m
    try {
        md = MessageDigest.getInstance(_algorithm);
    } catch (NoSuchAlgorithmException e) {
        throw new SystemUnavailableException(e.getMessage());
    }
    try {
        md.update(plaintext.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new SystemUnavailableException(e.getMessage());
    }

    byte raw[] = md.digest(); //step 4
    String hash = new String((new Base64()).encode(raw));
    return hash; //step 6
}

From source file:securitytools.common.http.TrustingSSLConnectionSocketFactory.java

private SSLContext getSSLContext() throws IOException {
    if (sslContext == null) {
        try {/*from w  w  w  . j  a va 2s  .com*/
            sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, new TrustManager[] { new TrustingX509TrustManager() }, null);
        } catch (NoSuchAlgorithmException nsae) {
            throw new IOException(nsae.getMessage(), nsae);
        } catch (KeyManagementException kme) {
            throw new IOException(kme.getMessage(), kme);
        }
    }
    return sslContext;
}

From source file:com.rockagen.gnext.service.spring.AuthUserServImpl.java

private void newPassword(final AuthUser po, final String newPass) {
    try {/*  w  w w .j a  va 2  s. co m*/
        String salt = Crypto.getHexSalt();
        String cipher = Crypto.sha1WithSalt(newPass, salt);
        po.setSalt(salt);
        po.setPassWord(cipher);
    } catch (NoSuchAlgorithmException e) {
        log.error("{}", e.getMessage(), e);
    } catch (NoSuchProviderException e) {
        log.error("{}", e.getMessage(), e);
    }
}

From source file:no.sesat.search.util.TradeDoubler.java

public String getChecksum(final String orderNumber, final String orderValue) throws RuntimeException {

    MessageDigest digest = null;/*from  ww w.j  a  va 2 s . c  o  m*/
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage());
    }
    final String s = new String(TradeDoubler.getSecretCode() + orderNumber + orderValue);
    digest.update(s.getBytes());
    return new String(Hex.encodeHex(digest.digest()));
}

From source file:ch.cyberduck.core.b2.B2SingleUploadService.java

@Override
protected MessageDigest digest() throws IOException {
    MessageDigest digest = null;// w  w w  .  jav  a  2s  .  c o  m
    if (PreferencesFactory.get().getBoolean("b2.upload.checksum.verify")) {
        try {
            digest = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            throw new IOException(e.getMessage(), e);
        }
    }
    return digest;
}