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(); }
/** * 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 byte[] computeMd5Bytes(InputStream is, long remaining) throws IOException { byte readBuff[] = new byte[4096]; MessageDigest digest = MD5_DIGEST.get(); digest.reset(); int read; while (remaining > 0 && (read = is.read(readBuff)) != -1) { int updateLen = (int) Math.min(remaining, read); digest.update(readBuff, 0, updateLen); remaining -= updateLen; } return digest.digest(); }
MCMPAdvertiseTask(final ModClusterContainer container, final MCMPConfig.AdvertiseConfig config, final MulticastMessageChannel channel) throws IOException { this.container = container; this.protocol = config.getProtocol(); // MODCLUSTER-483 mod_cluster client does not yet support ipv6 addresses with zone indices so skip it String host = config.getManagementSocketAddress().getHostString(); int zoneIndex = host.indexOf("%"); this.host = (zoneIndex < 0) ? host : host.substring(0, zoneIndex); this.port = config.getManagementSocketAddress().getPort(); this.path = config.getPath(); this.channel = channel; final InetAddress group = InetAddress.getByName(config.getAdvertiseGroup()); address = new InetSocketAddress(group, config.getAdvertisePort()); try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } final String securityKey = config.getSecurityKey(); if (securityKey == null) { // Security key is not configured, so the result hash was zero bytes ssalt = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; } else { md.reset(); digestString(md, securityKey); ssalt = md.digest(); } UndertowLogger.ROOT_LOGGER.proxyAdvertisementsStarted(address.toString(), config.getAdvertiseFrequency()); }
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(); }
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; }
/** * Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is * standard procedure in Bitcoin. The resulting hash is in big endian form. */ public static byte[] doubleDigest(byte[] input, int offset, int length) { synchronized (digest) { digest.reset(); digest.update(input, offset, length); byte[] first = digest.digest(); return digest.digest(first); } }
MessageDigest sha1 = null; try { sha1 = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { Timber.e(e, "Error while initializing MessageDigest"); sha1.reset(); try { String sha1sum = Hex.encodeHex(sha1.digest(chain[i].getEncoded())); chainInfo.append("Fingerprint (SHA-1): ").append(sha1sum).append("\n"); } catch (CertificateEncodingException e) {
public TTTDEnumeration(InputStream in) throws IOException { this.in = in; this.closed = false; this.c = new byte[8192]; this.clen = -1; this.cpos = -1; try { fingerprinter = Fingerprinter.getInstance(fingerprintAlgorithm); chunkDigest = MessageDigest.getInstance(checksumAlgorithm); fileDigest = MessageDigest.getInstance(checksumAlgorithm); fileDigest.reset(); } catch (Exception e) { throw new RuntimeException(e); } }
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; }
MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); int read = 0; DigestInputStream is = new DigestInputStream(f.getInputStream(), md5); is.close(); byte[] digest = md5.digest(); System.out.println("length: " + read + " md5: " + Util.toHex(digest)); return;
/** * Default constructor setting the GridFS file name and providing an input stream containing data to be written to the file. * * @param gridFS The GridFS connection handle. * @param inputStream Stream used for reading data from. * @param filename Name of the file to be created. * @param closeStreamOnPersist indicate the passed in input stream should be closed once the data chunk persisted */ protected GridFSInputFile(final GridFS gridFS, final InputStream inputStream, final String filename, final boolean closeStreamOnPersist) { this.fs = gridFS; this.inputStream = inputStream; this.filename = filename; this.closeStreamOnPersist = closeStreamOnPersist; this.id = new ObjectId(); this.chunkSize = GridFS.DEFAULT_CHUNKSIZE; this.uploadDate = new Date(); try { this.messageDigester = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("No MD5!"); } this.messageDigester.reset(); this.buffer = new byte[(int) chunkSize]; }