import java.security.*; .. byte[] bytesOfMessage = yourString.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] thedigest = md.digest(bytesOfMessage);
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(); }
String plaintext = "your text here"; MessageDigest m = MessageDigest.getInstance("MD5"); m.reset(); m.update(plaintext.getBytes()); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1,digest); String hashtext = bigInt.toString(16); // Now we need to zero pad it if you actually want the full 32 chars. while(hashtext.length() < 32 ){ hashtext = "0"+hashtext; }
Security.addProvider(new BouncyCastleProvider()); String data = "hello world"; MessageDigest mda = MessageDigest.getInstance("SHA-512", "BC"); byte [] digesta = mda.digest(data.getBytes()); MessageDigest mdb = MessageDigest.getInstance("SHA-512", "BC"); byte [] digestb = mdb.digest(data.getBytes()); System.out.println(MessageDigest.isEqual(digesta, digestb)); System.out.println(Hex.encodeHex(digesta));
public static byte[] md5Bytes(String text) { MessageDigest msgDigest = null; try { msgDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("System doesn't support MD5 algorithm."); } msgDigest.update(text.getBytes()); byte[] bytes = msgDigest.digest(); return bytes; }
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(); }
protected String generateKey(Map<String, String> values) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); byte[] bytes = digest.digest(values.toString().getBytes("UTF-8")); return String.format("%032x", new BigInteger(1, bytes)); } catch (NoSuchAlgorithmException nsae) { throw new IllegalStateException("MD5 algorithm not available. Fatal (should be in the JDK).", nsae); } catch (UnsupportedEncodingException uee) { throw new IllegalStateException("UTF-8 encoding not available. Fatal (should be in the JDK).", uee); } } }
/** * Returns the fingerprint of the public key. * * @return the fingerprint of the public key. */ public String getFingerprint() { RSAPublicKey key = InstanceIdentityProvider.RSA.getPublicKey(); if (key == null) { return null; } // TODO replace with org.jenkinsci.remoting.util.KeyUtils once JENKINS-36871 changes are merged try { MessageDigest digest = MessageDigest.getInstance("MD5"); digest.reset(); byte[] bytes = digest.digest(key.getEncoded()); StringBuilder result = new StringBuilder(Math.max(0, bytes.length * 3 - 1)); for (int i = 0; i < bytes.length; i++) { if (i > 0) { result.append(':'); } int b = bytes[i] & 0xFF; result.append(Character.forDigit((b>>4)&0x0f, 16)).append(Character.forDigit(b&0xf, 16)); } return result.toString(); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("JLS mandates MD5 support"); } } }
public FixedChunkEnumeration(InputStream in) { this.in = in; this.buffer = new byte[chunkSize]; this.closed = false; try { this.digest = MessageDigest.getInstance(checksumAlgorithm); this.fileDigest = MessageDigest.getInstance(checksumAlgorithm); this.fileDigest.reset(); } catch (Exception e) { throw new RuntimeException(e); } }
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 static String calcClassSign(String name) { try { Class<?> clazz = Class.forName(name); ByteArrayOutputStream result = new ByteArrayOutputStream(); ObjectOutputStream outputStream = new ObjectOutputStream(result); outputStream.writeObject(clazz); outputStream.close(); MessageDigest crypt = MessageDigest.getInstance("SHA-1"); crypt.reset(); crypt.update(result.toByteArray()); return new BigInteger(1, crypt.digest()).toString(16); } catch (Exception e) { throw new IllegalStateException("Can't calculate sign of " + name, e); } }
Certificate cert = keystore.getCertificate("adhoc"); byte[] certBytes = cert.getEncoded(); byte[] sha1 = MessageDigest.getInstance("SHA1").digest(certBytes); startupOut.print("Using ad-hoc HTTPS certificate with fingerprint...\nSHA1"); for(byte b : sha1) { startupOut.print(String.format(":%02X",b)); startupOut.println("\nVerify in browser before accepting exception."); } catch (Exception e) {
/** * get md5 in byte array * * @param buffer data to be calculated * @return md5 result in byte array format */ public static byte[] getRawDigest(byte[] buffer) { try { MessageDigest mdTemp = MessageDigest.getInstance("MD5"); mdTemp.update(buffer); return mdTemp.digest(); } catch (Exception e) { return null; } }
MessageDigest md = MessageDigest.getInstance("MD5"); try (InputStream is = Files.newInputStream(Paths.get("file.txt")); DigestInputStream dis = new DigestInputStream(is, md)) { /* Read decorated stream (dis) to EOF as normal... */ } byte[] digest = md.digest();
public static String hashData(String in) { MessageDigest md; try { md = MessageDigest.getInstance("SHA-1"); byte[] hash = md.digest((HASH_SEED + in).getBytes("UTF-8")); return String.format("%040x", new BigInteger(1, hash)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
public static final byte[] scramble411(byte[] pass, byte[] seed) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] pass1 = md.digest(pass); md.reset(); byte[] pass2 = md.digest(pass1); md.reset(); md.update(seed); byte[] pass3 = md.digest(pass2); for (int i = 0; i < pass3.length; i++) { pass3[i] = (byte) (pass3[i] ^ pass1[i]); } return pass3; }
@Override public String rename(String filePath) { try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(filePath.getBytes()); return new BigInteger(1, md.digest()).toString(32); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; } })
String decodedtext = new TripleDESTest().decrypt(codedtext); System.out.println(codedtext); // this is a byte array, you'll just see a reference to an array System.out.println(decodedtext); // This correctly shows "kyle boon" final MessageDigest md = MessageDigest.getInstance("md5"); final byte[] digestOfPassword = md.digest("HG58YZ3CR9" .getBytes("utf-8")); final byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); final MessageDigest md = MessageDigest.getInstance("md5"); final byte[] digestOfPassword = md.digest("HG58YZ3CR9" .getBytes("utf-8")); final byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
try { PackageInfo info = getPackageManager().getPackageInfo( "com.example.packagename", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { }
private @Nonnull byte[] hashedBytes(byte[] tokenBytes) { MessageDigest digest; try { digest = MessageDigest.getInstance(HASH_ALGORITHM); } catch (NoSuchAlgorithmException e) { throw new AssertionError("There is no " + HASH_ALGORITHM + " available in this system"); } return digest.digest(tokenBytes); }