Package java.security

Examples of java.security.MessageDigest$MessageDigestImpl


            try {
                URL url = new URL(sku);
                String host = url.getHost();
                if (host == null) throw new IOException("charding - bad url, host empty: " + sku);
                try {
                    MessageDigest digest = MessageDigest.getInstance("MD5");
                    digest.update(host.getBytes(charsetUTF8));
                    byte[] md5 = digest.digest();
                    return (0xff & md5[0]) % this.dimension;
                } catch (NoSuchAlgorithmException e) {
                    throw new IOException("charding - no md5 available: " + e.getMessage());
                }
            } catch (MalformedURLException e) {
View Full Code Here


     * @param string string to hash
     * @return hashed string
     */
    public static String digest(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        byte[] b = string.getBytes();
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(b);
        byte[] digest = md.digest();
        return new String(digest);
    }
View Full Code Here

      return Base64.encodeBytes(bodyHash);
   }

   private byte[] hash(byte[] body, String hashAlgorithm) throws SignatureException
   {
      MessageDigest digest = null;
      try
      {
         digest = MessageDigest.getInstance(hashAlgorithm);
      }
      catch (Exception e)
      {
         throw new SignatureException(e);
      }

      int length = body.length;

      if (attributes.containsKey(LENGTH))
      {
         length = Integer.parseInt(attributes.get(LENGTH));
      }

      byte[] bodyHash = null;
      digest.update(body, 0, length);
      bodyHash = digest.digest();
      return bodyHash;
   }
View Full Code Here

   protected String createHash(byte[] entity)
   {
      try
      {
         MessageDigest messagedigest = MessageDigest.getInstance("MD5");
         byte abyte0[] = messagedigest.digest(entity);
         return byteArrayToHexString(abyte0);
      }
      catch (NoSuchAlgorithmException e)
      {
         throw new RuntimeException(e);
View Full Code Here

            '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
    };

    public String hash(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance(hashFunction);
            md.update(text.getBytes(charset));
            byte[] raw = md.digest();
            return new String(encodeHex(raw));
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

    String hashFunction = "MD5";
    String charset      = "UTF-8";
   
    public String hash(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance(hashFunction);
            md.update(password.getBytes(charset));
            byte[] raw = md.digest();
            return new String(Hex.encodeHex(raw));
        }
        catch (Exception e) {
            throw new RuntimeException(e);       
        }
View Full Code Here

        // generate a hex representation from the md5 of a byte-array
        return encodeHex(encodeMD5Raw(b));
    }

    public static byte[] encodeMD5Raw(final String key) {
      MessageDigest digest = null;
      boolean fromPool = true;
      if (digestPool.size() == 0) {
          // if there are no digest objects left, create some on the fly
          // this is not the most effective way but if we wouldn't do that the encoder would block
          try {
                digest = MessageDigest.getInstance("MD5");
                digest.reset();
                fromPool = false;
            } catch (final NoSuchAlgorithmException e) {
            }
      }
        if (digest == null) try {
            digest = digestPool.take();
        } catch (final InterruptedException e) {
          Log.logWarning("Digest", "using generic instead of pooled digest");
          try {
        digest = MessageDigest.getInstance("MD5");
      } catch (final NoSuchAlgorithmException e1) {
          Log.logException(e1);
      }
      digest.reset();
      fromPool = false;
    }
        byte[] keyBytes;
        keyBytes = UTF8.getBytes(key);
        digest.update(keyBytes);
        final byte[] result = digest.digest();
        digest.reset();
        if (fromPool) {
            returntopool: while (true) {
                try {
                    digestPool.put(digest);
                    break returntopool;
View Full Code Here

     */
    public static byte[] fastFingerprintRaw(final File file, final boolean includeDate) throws IOException {
        final int mb = 16 * 1024;
        final long fl = file.length();
        if (fl <= 2 * mb) return encodeMD5Raw(file);
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (final NoSuchAlgorithmException e) {
            Log.logException(e);
            return null;
        }
        final RandomAccessFile raf = new RandomAccessFile(file, "r");
        final byte[] a = new byte[mb];
        try {
            raf.seek(0);
            raf.readFully(a, 0, mb);
            digest.update(a, 0, mb);
            raf.seek(fl - mb);
            raf.readFully(a, 0, mb);
            digest.update(a, 0, mb);
            digest.update(NaturalOrder.encodeLong(fl, 8), 0, 8);
            if (includeDate) digest.update(NaturalOrder.encodeLong(file.lastModified(), 8), 0, 8);
        } finally {
            raf.close();
            try {raf.getChannel().close();} catch (final IOException e) {}
        }
        return digest.digest();
    }
View Full Code Here

        return digest.digest();
    }

    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());
        }
View Full Code Here

        buf.putInt(key2);
        buf.putLong(num);
        buf.flip();
       
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(buf.array());
            return md5.digest();
        } catch (NoSuchAlgorithmException nse) {
            throw new IOException(nse.toString());
        }
    }
View Full Code Here

TOP

Related Classes of java.security.MessageDigest$MessageDigestImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.