List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:net.sourceforge.jaulp.file.checksum.ChecksumUtils.java
/** * Gets the checksum quietly from the given byte array with an instance of. * * @param bytes/*from w ww. j a v a 2 s. co m*/ * the byte array. * @param algorithm * the algorithm to get the checksum. This could be for instance "MD4", "MD5", * "SHA-1", "SHA-256", "SHA-384" or "SHA-512". * @return The checksum from the file as a String object. */ public static String getChecksumQuietly(byte[] bytes, String algorithm) { try { return getChecksum(bytes, algorithm); } catch (NoSuchAlgorithmException e) { LOGGER.error("getChecksumQuietly failed...\n" + e.getMessage(), e); } return algorithm; }
From source file:net.sourceforge.jaulp.file.checksum.ChecksumUtils.java
/** * Gets the checksum quietly from the given byte array with an instance of. * * @param bytes//from w w w . j a va 2 s .co m * the Byte object array. * @param algorithm * the algorithm to get the checksum. This could be for instance "MD4", "MD5", * "SHA-1", "SHA-256", "SHA-384" or "SHA-512". * @return The checksum from the file as a String object. */ public static String getChecksumQuietly(Byte[] bytes, String algorithm) { try { return getChecksum(bytes, algorithm); } catch (NoSuchAlgorithmException e) { LOGGER.error("getChecksumQuietly failed...\n" + e.getMessage(), e); } return algorithm; }
From source file:com.cws.esolutions.security.utils.PasswordUtils.java
/** * Provides one-way (irreversible) encryption of a provided string. * * @param plainText - The plain text data to encrypt * @param salt - The salt value to utilize for the request * @param instance - The security instance to utilize * @param iterations - The number of times the value should be re-encrypted * @param encoding - The text encoding/* ww w . j av a 2 s. c o m*/ * @return The encrypted string * @throws SecurityException {@link java.lang.SecurityException} if an exception occurs during processing */ public static final String encryptText(final String plainText, final String salt, final String instance, final int iterations, final String encoding) throws SecurityException { final String methodName = PasswordUtils.CNAME + "#encryptText(final String plainText, final String salt, final String algorithm, final String instance, final int iterations, final String encoding) throws SecurityException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", plainText); DEBUGGER.debug("Value: {}", salt); DEBUGGER.debug("Value: {}", instance); DEBUGGER.debug("Value: {}", iterations); DEBUGGER.debug("Value: {}", encoding); } String response = null; try { MessageDigest md = MessageDigest.getInstance(instance); md.reset(); md.update(salt.getBytes(encoding)); byte[] input = md.digest(plainText.getBytes(encoding)); for (int x = 0; x < iterations; x++) { md.reset(); input = md.digest(input); } response = Base64.getEncoder().encodeToString(input); } catch (NoSuchAlgorithmException nsx) { throw new SecurityException(nsx.getMessage(), nsx); } catch (UnsupportedEncodingException uex) { throw new SecurityException(uex.getMessage(), uex); } return response; }
From source file:org.kuali.kra.s2s.generator.S2SBaseFormGenerator.java
/** * //from w w w. j a v a 2 s .co m * This method is used to encode the hash value based on Message Digest * * @param attachment * @return Base64.encode(rawDigest) (String) */ protected final static String computeAttachmentHash(byte[] attachment) { org.apache.xml.security.Init.init(); MessageDigest messageDigester; try { messageDigester = MessageDigest.getInstance(S2SConstants.HASH_ALGORITHM); byte[] rawDigest = messageDigester.digest(attachment); return Base64.encode(rawDigest); } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage(), e); return ""; } }
From source file:com.glaf.core.security.SecurityUtils.java
public static String hash(String plaintext) { MessageDigest md = null;// w w w .ja va 2s . c o m try { md = MessageDigest.getInstance("SHA"); // SHA-1 generator instance } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } try { md.update(plaintext.getBytes("UTF-8")); // Message summary // generation } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage()); } byte raw[] = md.digest(); // Message summary reception try { String hash = new String(org.apache.commons.codec.binary.Base64.encodeBase64(raw), "UTF-8"); return hash; } catch (UnsupportedEncodingException use) { throw new RuntimeException(use); } }
From source file:org.artifactory.security.crypto.CryptoHelper.java
public static KeyPair generateKeyPair() { try {//from w w w . j a v a2 s . com KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ASYM_ALGORITHM); SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); keyGen.initialize(512, random); return keyGen.generateKeyPair(); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("No such algorithm:" + e.getMessage()); } }
From source file:de.alpharogroup.file.checksum.ChecksumExtensions.java
/** * Gets the checksum quietly from the given byte array with an instance of. * * @param bytes/*from w w w . j a v a 2 s.c o m*/ * the byte array. * @param algorithm * the algorithm to get the checksum. This could be for instance "MD4", "MD5", * "SHA-1", "SHA-256", "SHA-384" or "SHA-512". * @return The checksum from the file as a String object. */ public static String getChecksumQuietly(final byte[] bytes, final Algorithm algorithm) { try { return getChecksum(bytes, algorithm.getAlgorithm()); } catch (final NoSuchAlgorithmException e) { LOGGER.error("getChecksumQuietly failed...\n" + e.getMessage(), e); } return null; }
From source file:de.alpharogroup.file.checksum.ChecksumExtensions.java
/** * Gets the checksum quietly from the given file with an instance of the given algorithm. * * @param file/*from w w w .j a v a 2 s . com*/ * the file. * @param algorithm * the algorithm to get the checksum. This could be for instance "MD4", "MD5", * "SHA-1", "SHA-256", "SHA-384" or "SHA-512". * @return The checksum from the file as a String object or null if a NoSuchAlgorithmException * will be thrown. exists. {@link java.security.MessageDigest} object. */ public static String getChecksumQuietly(final File file, final Algorithm algorithm) { try { return getChecksum(file, algorithm.getAlgorithm()); } catch (final NoSuchAlgorithmException e) { LOGGER.error("getChecksumQuietly failed...\n" + e.getMessage(), e); } return null; }
From source file:org.artifactory.security.crypto.CryptoHelper.java
private static SecretKey generatePbeKey(String password) { try {/*from w ww .j a v a 2 s . c o m*/ PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(SYM_ALGORITHM); SecretKey secretKey = keyFactory.generateSecret(pbeKeySpec); return secretKey; } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("No such algorithm: " + e.getMessage()); } catch (InvalidKeySpecException e) { throw new RuntimeException("Unexpected exception: ", e); } }
From source file:de.alpharogroup.file.checksum.ChecksumExtensions.java
/** * Gets the checksum quietly from the given byte array with an instance of. * * @param bytes/*w ww . j a va 2 s . c om*/ * the byte array. * @param algorithm * the algorithm to get the checksum. This could be for instance "MD4", "MD5", * "SHA-1", "SHA-256", "SHA-384" or "SHA-512". * @return The checksum from the file as a String object. */ public static String getChecksumQuietly(final byte[] bytes, final String algorithm) { try { return getChecksum(bytes, algorithm); } catch (final NoSuchAlgorithmException e) { LOGGER.error("getChecksumQuietly failed...\n" + e.getMessage(), e); } return algorithm; }