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:com.crawler.app.run.CrawlSiteController.java

public static String hashHTML(String input) {
    try {//from  w  ww.  j  a  v a 2s . c  o  m
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(input.getBytes());
        byte[] enc = md.digest();
        String md5Sum = new sun.misc.BASE64Encoder().encode(enc);
        return md5Sum;

    } catch (NoSuchAlgorithmException nsae) {

        System.out.println(nsae.getMessage());
        return null;
    }

}

From source file:finale.year.stage.utility.Util.java

public static JSONObject signUp(String email, String password, String id) {
    HttpJSONExchange exchange = new HttpJSONExchange();

    HashMap<String, String> headers = new HashMap<>();
    HashMap<String, String> params = new HashMap<>();
    String url = ROOT + "register";

    headers.put("User-Agent", "desktop");
    params.put("email", email);
    try {//ww  w. jav  a  2 s .c  o  m
        params.put("password", encryptPassword(password));
    } catch (NoSuchAlgorithmException ex) {
        Inscription.updateStatus("Sign Up Error : " + ex.getMessage());
    }
    params.put("id", id);

    JSONObject json = null;
    if (isAv(mainF.mainFrame)) //Check Internet Connection 
        json = exchange.sendPOSTRequest(url, params, headers);

    //Return Result to InscriptionWindow
    return json;
}

From source file:net.nicholaswilliams.java.licensing.encryption.Encryptor.java

private static Cipher getEncryptionCipher(SecretKey secretKey) {
    try {//  www.  ja  v a 2  s . c  om
        Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm());
        cipher.init(Cipher.ENCRYPT_MODE, secretKey, Encryptor.random);
        return cipher;
    } catch (NoSuchAlgorithmException e) {
        throw new AlgorithmNotSupportedException("AES With SHA-1 digest", e);
    } catch (NoSuchPaddingException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeyException e) {
        throw new InappropriateKeyException(e.getMessage(), e);
    }
}

From source file:net.nicholaswilliams.java.licensing.encryption.Encryptor.java

private static Cipher getDecryptionCipher(SecretKey secretKey) {
    try {//from   www .  ja  v  a2s  . c  om
        Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm());
        cipher.init(Cipher.DECRYPT_MODE, secretKey, Encryptor.random);
        return cipher;
    } catch (NoSuchAlgorithmException e) {
        throw new AlgorithmNotSupportedException("AES With SHA-1 digest", e);
    } catch (NoSuchPaddingException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (InvalidKeyException e) {
        throw new InappropriateKeyException(e.getMessage(), e);
    }
}

From source file:be.fedict.eid.applet.service.signer.facets.XAdESSignatureFacet.java

/**
 * Gives back the JAXB DigestAlgAndValue data structure.
 * /*  ww  w.jav  a 2 s  . c o  m*/
 * @param data
 * @param xadesObjectFactory
 * @param xmldsigObjectFactory
 * @param digestAlgorithm
 * @return
 */
public static DigestAlgAndValueType getDigestAlgAndValue(byte[] data, ObjectFactory xadesObjectFactory,
        be.fedict.eid.applet.service.signer.jaxb.xmldsig.ObjectFactory xmldsigObjectFactory,
        DigestAlgo digestAlgorithm) {
    DigestAlgAndValueType digestAlgAndValue = xadesObjectFactory.createDigestAlgAndValueType();

    DigestMethodType digestMethod = xmldsigObjectFactory.createDigestMethodType();
    digestAlgAndValue.setDigestMethod(digestMethod);
    digestMethod.setAlgorithm(digestAlgorithm.getXmlAlgoId());

    MessageDigest messageDigest;
    try {
        messageDigest = MessageDigest.getInstance(digestAlgorithm.getAlgoId());
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("message digest algo error: " + e.getMessage(), e);
    }
    byte[] digestValue = messageDigest.digest(data);
    digestAlgAndValue.setDigestValue(digestValue);

    return digestAlgAndValue;
}

From source file:com.piusvelte.taplock.server.TapLockServer.java

protected static SecretKey getSecretKey(KeyStore ks) {
    SecretKey sk = null;//from   w w w  .  j  av a 2  s  . c  om
    if (ks != null) {
        boolean ksLoaded = false;
        try {
            ks.load(new FileInputStream(sKeystore), sPassphrase.toCharArray());
            ksLoaded = true;
        } catch (NoSuchAlgorithmException e) {
            writeLog("getSecretKey: " + e.getMessage());
        } catch (CertificateException e) {
            writeLog("getSecretKey: " + e.getMessage());
        } catch (FileNotFoundException e) {
            writeLog("getSecretKey: " + e.getMessage());
        } catch (IOException e) {
            writeLog("getSecretKey: " + e.getMessage());
        }
        if (ksLoaded) {
            try {
                sk = (SecretKey) ks.getKey(TAP_LOCK, sPassphrase.toCharArray());
            } catch (UnrecoverableKeyException e) {
                writeLog("getSecretKey: " + e.getMessage());
            } catch (KeyStoreException e) {
                writeLog("getSecretKey: " + e.getMessage());
            } catch (NoSuchAlgorithmException e) {
                writeLog("getSecretKey: " + e.getMessage());
            }
        }
    }
    return sk;
}

From source file:com.piusvelte.taplock.server.TapLockServer.java

protected static String decryptString(String encStr) {
    String decStr = null;//from ww  w.jav a 2 s.c o m
    KeyStore ks = getKeyStore();
    if (ks != null) {
        SecretKey sk = getSecretKey(ks);
        if (sk != null) {
            Cipher cipher;
            try {
                cipher = Cipher.getInstance("AES");
                cipher.init(Cipher.DECRYPT_MODE, sk);
                return new String(cipher.doFinal(Base64.decodeBase64(encStr)), "UTF-8");
            } catch (NoSuchAlgorithmException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (NoSuchPaddingException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (InvalidKeyException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (UnsupportedEncodingException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (IllegalBlockSizeException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (BadPaddingException e) {
                writeLog("encryptString: " + e.getMessage());
            }
        }
    }
    return decStr;
}

From source file:com.piusvelte.taplock.server.TapLockServer.java

protected static String encryptString(String decStr) {
    String encStr = null;/*from   w  ww .  j  av a  2 s  .com*/
    KeyStore ks = getKeyStore();
    if (ks != null) {
        SecretKey sk = getSecretKey(ks);
        if (sk == null) {
            // create key
            KeyGenerator kgen = null;
            try {
                kgen = KeyGenerator.getInstance("AES");
            } catch (NoSuchAlgorithmException e) {
                writeLog("encryptString: " + e.getMessage());
            }
            if (kgen != null) {
                int keyLength;
                try {
                    keyLength = Cipher.getMaxAllowedKeyLength("AES");
                } catch (NoSuchAlgorithmException e) {
                    keyLength = 128;
                    writeLog("encryptString: " + e.getMessage());
                }
                kgen.init(keyLength);
                sk = kgen.generateKey();
                // create a keystore
                try {
                    ks.load(null, sPassphrase.toCharArray());
                    ks.setKeyEntry(TAP_LOCK, sk, sPassphrase.toCharArray(), null);
                    ks.store(new FileOutputStream(sKeystore), sPassphrase.toCharArray());
                } catch (NoSuchAlgorithmException e) {
                    writeLog("encryptString: " + e.getMessage());
                } catch (CertificateException e) {
                    writeLog("encryptString: " + e.getMessage());
                } catch (IOException e) {
                    writeLog("encryptString: " + e.getMessage());
                } catch (KeyStoreException e) {
                    writeLog("encryptString: " + e.getMessage());
                }
            }
        }
        if ((sk != null) && (decStr != null)) {
            Cipher cipher;
            try {
                cipher = Cipher.getInstance("AES");
                cipher.init(Cipher.ENCRYPT_MODE, sk);
                return new String(Base64.encodeBase64(cipher.doFinal(decStr.getBytes("UTF-8"))));
            } catch (NoSuchAlgorithmException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (NoSuchPaddingException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (InvalidKeyException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (IllegalBlockSizeException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (BadPaddingException e) {
                writeLog("encryptString: " + e.getMessage());
            } catch (UnsupportedEncodingException e) {
                writeLog("encryptString: " + e.getMessage());
            }
        }
    }
    return encStr;
}

From source file:org.photovault.imginfo.ImageFile.java

/**
 *     Utility function to calculate the hash of a specific file
 * @param f The file//from www  .  j av  a2 s . co m
 * @return Hash of f
 */
public static byte[] calcHash(File f) {
    FileInputStream is = null;
    byte hash[] = null;
    try {
        is = new FileInputStream(f);
        byte readBuffer[] = new byte[4096];
        MessageDigest md = MessageDigest.getInstance("MD5");
        int bytesRead = -1;
        while ((bytesRead = is.read(readBuffer)) > 0) {
            md.update(readBuffer, 0, bytesRead);
        }
        hash = md.digest();
    } catch (NoSuchAlgorithmException ex) {
        log.error("MD5 algorithm not found");
    } catch (FileNotFoundException ex) {
        log.error(f.getAbsolutePath() + "not found");
    } catch (IOException ex) {
        log.error("IOException while calculating hash: " + ex.getMessage());
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException ex) {
            log.error("Cannot close stream after calculating hash");
        }
    }
    return hash;
}

From source file:com.aegiswallet.utils.WalletUtils.java

public static String convertToSha256(String plainText) {

    String result = null;//from w  ww. ja v  a2 s  .co  m
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(plainText.getBytes());

        byte byteData[] = md.digest();

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }

        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            String hex = Integer.toHexString(0xff & byteData[i]);
            if (hex.length() == 1)
                hexString.append('0');
            hexString.append(hex);
        }

        result = hexString.toString();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, e.getMessage());
    } finally {
        return result;
    }
}