Refine search
private byte[] md5(String value) { MessageDigest md5; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e.getMessage(), e); } md5.reset(); byte[] bytes = value.getBytes(StandardCharsets.UTF_8); md5.update(bytes); return md5.digest(); }
private byte[] md5(String value) { MessageDigest md5; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e.getMessage(), e); } md5.reset(); byte[] bytes = value.getBytes(StandardCharsets.UTF_8); md5.update(bytes); return md5.digest(); }
@Override protected MessageDigest initialValue() { try { return MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new SdkClientException( "Unable to get SHA256 Function" + e.getMessage(), e); } } });
private static byte[] hash( byte[] salt, byte[] password ) { try { MessageDigest m = MessageDigest.getInstance( DIGEST_ALGO ); m.update( salt, 0, salt.length ); m.update( password, 0, password.length ); return m.digest(); } catch ( NoSuchAlgorithmException e ) { throw new RuntimeException( "Hash algorithm is not available on this platform: " + e.getMessage(), e ); } }
/** * Returns an SHA digest. * * @return An SHA digest instance. * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is * caught. */ private static MessageDigest getSha512Digest() { try { return MessageDigest.getInstance("SHA-512"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } }
/** * Returns an SHA digest. * * @return An SHA digest instance. * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is * caught. */ private static MessageDigest getSha512Digest() { try { return MessageDigest.getInstance("SHA-512"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } }
private static byte[] sha256(byte[] bytes) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(bytes); return md.digest(); } catch (NoSuchAlgorithmException e) { throw new UnsupportedOperationException(e.getMessage(), e); } } }
public VircurexSha2Digest( String aSecretWord, String aUserName, String aTimeStamp, long aNonce, String aMethod) { try { digest = MessageDigest.getInstance(SHA_256); digest.update( (aSecretWord + ";" + aUserName + ";" + aTimeStamp + ";" + aNonce + ";" + aMethod) .getBytes()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage(), e); } secretWord = DigestUtils.bytesToHex(digest.digest()); }
/** * Returns the message digest. * * @param algorithm the algorithm for the message digest * @return the message digest */ private static MessageDigest getMessageDigest(String algorithm) { try { return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { LOGGER.error(e.getMessage()); final String msg = String.format("Failed to obtain the %s message digest.", algorithm); throw new IllegalStateException(msg, e); } } }
/** * Md 5 byte [ ]. * * @param value the value * @return the byte [ ] */ private byte[] md5(final String value) { MessageDigest md5; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e.getMessage(), e); } md5.reset(); byte[] bytes; bytes = value.getBytes(StandardCharsets.UTF_8); md5.update(bytes); return md5.digest(); }
public md5FilechunkConsumer(final int bufferSize, final int bufferCount) { this.empty = new ArrayBlockingQueue<filechunk>(bufferCount); this.filed = new LinkedBlockingQueue<filechunk>(); // fill the empty queue for (int i = 0; i < bufferCount; i++) this.empty.add(new filechunk(bufferSize)); // init digest try { this.digest = MessageDigest.getInstance("MD5"); } catch (final NoSuchAlgorithmException e) { System.out.println("Internal Error at md5:" + e.getMessage()); } this.digest.reset(); }
/** * Get the signature of the input string based on SHA digest algorithm. * @param str Input token * @return Signed String */ private String getSignature(String str) { try { MessageDigest md = MessageDigest.getInstance(SHA_STRING); md.update(str.getBytes()); md.update(secretBytes); byte[] digest = md.digest(); return new Base64(0).encodeToString(digest); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException("Invalid SHA digest String: " + SHA_STRING + " " + ex.getMessage(), ex); } } }
private static byte[] encodeMD5Raw(final byte[] b) { try { final MessageDigest digest = MessageDigest.getInstance("MD5"); digest.reset(); final InputStream in = new ByteArrayInputStream(b); final byte[] buf = new byte[2048]; int n; while ((n = in.read(buf)) > 0) digest.update(buf, 0, n); in.close(); // now compute the hex-representation of the md5 digest return digest.digest(); } catch (final java.security.NoSuchAlgorithmException e) { System.out.println("Internal Error at md5:" + e.getMessage()); } catch (final java.io.IOException e) { System.out.println("byte[] error: " + e.getMessage()); } return null; }
/** * Colon separated value MD5 hash. * * @param tokens one or more strings * @return M5 hash string * @throws IOException */ private static String md5(final String... tokens) throws IOException { final StringBuilder sb = new StringBuilder(100); for (final String token : tokens) { if (sb.length() > 0) { sb.append(':'); } sb.append(token); } final MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (final NoSuchAlgorithmException ex) { throw new IOException(ex.getMessage()); } md.update(sb.toString().getBytes(HttpAuthenticationFilter.CHARACTER_SET), 0, sb.length()); final byte[] md5hash = md.digest(); return bytesToHex(md5hash); }
/** * Colon separated value MD5 hash. * * @param tokens one or more strings * @return M5 hash string * @throws IOException */ private static String md5(final String... tokens) throws IOException { final StringBuilder sb = new StringBuilder(100); for (final String token : tokens) { if (sb.length() > 0) { sb.append(':'); } sb.append(token); } final MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (final NoSuchAlgorithmException ex) { throw new IOException(ex.getMessage()); } md.update(sb.toString().getBytes(HttpAuthenticationFilter.CHARACTER_SET), 0, sb.length()); final byte[] md5hash = md.digest(); return bytesToHex(md5hash); }
public VircurexSha2Digest( String aSecretWord, String aUserName, String aTimeStamp, long aNonce, String aMethod, String anOrderId) { try { digest = MessageDigest.getInstance(SHA_256); digest.update( (aSecretWord + ";" + aUserName + ";" + aTimeStamp + ";" + aNonce + ";" + aMethod + ";" + anOrderId) .getBytes()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage(), e); } secretWord = DigestUtils.bytesToHex(digest.digest()); }
/** * Converts a passphrase into a key, by following the convention that PuTTY uses. * <p/> * <p/> * This is used to decrypt the private key when it's encrypted. */ private byte[] toKey(final String passphrase) throws IOException { try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); // The encryption key is derived from the passphrase by means of a succession of SHA-1 hashes. // Sequence number 0 digest.update(new byte[]{0, 0, 0, 0}); digest.update(passphrase.getBytes()); byte[] key1 = digest.digest(); // Sequence number 1 digest.update(new byte[]{0, 0, 0, 1}); digest.update(passphrase.getBytes()); byte[] key2 = digest.digest(); byte[] r = new byte[32]; System.arraycopy(key1, 0, r, 0, 20); System.arraycopy(key2, 0, r, 20, 12); return r; } catch (NoSuchAlgorithmException e) { throw new IOException(e.getMessage(), e); } }
/** * Colon separated value MD5 hash. * * @param tokens one or more strings * @return M5 hash string * @throws ProxyAuthenticationException if MD5 algorithm cannot be instantiated */ private static String md5(String... tokens) throws ProxyAuthenticationException { StringBuilder sb = new StringBuilder(100); for (String token : tokens) { if (sb.length() > 0) { sb.append(':'); } sb.append(token); } MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException ex) { throw new ProxyAuthenticationException(ex.getMessage()); } md.update(sb.toString().getBytes(CHARACTER_SET), 0, sb.length()); byte[] md5hash = md.digest(); return bytesToHex(md5hash); }
/** Generate MD5 hash of topic and partitions. And extract first 4 characters of the MD5 hash. * @param topic topic name * @param partitions partitions * @return md5 hash */ public static String getMd5Hash(String topic, String[] partitions) { ArrayList<String> elements = new ArrayList<String>(); elements.add(topic); for (String partition : partitions) { elements.add(partition); } String pathPrefix = StringUtils.join(elements, "/"); try { final MessageDigest messageDigest = MessageDigest.getInstance("MD5"); byte[] md5Bytes = messageDigest.digest(pathPrefix.getBytes("UTF-8")); return getHexEncode(md5Bytes).substring(0, 4); } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage()); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage()); } return ""; }
MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); md5.update(str.getBytes("UTF-8")); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } catch (UnsupportedEncodingException e) { e.printStackTrace();