Package java.security

Examples of java.security.MessageDigest.digest()


            das.close();
        } catch (IOException e) {
            logger.warn("Cannot flush the stream", e);
        }

        byte[] digest = md.digest();
        long hash = 0;
        int size = Math.min(digest.length, BYTES_LENGTH);
        for (int i = 0; i < size; i++) {
            hash += (long) (digest[i] & BYTE_MASK) << (BYTES_LENGTH * i);
        }
View Full Code Here


    public DESCrypt(String password) {
        try {

            // Generate the key by taking the MD5 of the password
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Key = md5.digest(password.getBytes("UTF-8"));

            // Generate the key by compressing 8 bytes to 7
            byte[] inKey = new byte[8];
            inKey[0] = md5Key[0];
            inKey[1] = (byte) (((md5Key[0] & 0xFF) << 7) |
View Full Code Here

     *            The encryption password
     */
    public AESCrypt(String password) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Key = md5.digest(password.getBytes("UTF-8"));

            SecretKeySpec secretKey = new SecretKeySpec(md5Key, "AES");

            decrypter = Cipher.getInstance("AES/ECB/NoPadding");
            encrypter = Cipher.getInstance("AES/ECB/NoPadding");
View Full Code Here

    }

    public static String hash(char[] plaintext){
        try {
            MessageDigest sha = MessageDigest.getInstance(hashAlgorithm);
            byte[] hash = sha.digest(charArrayToByteArray(plaintext));
            return byteArrayToHexString(hash);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

                        jarSize++;
                        md.update( (byte)( data & 0xff ) );
                    }
                    m_outDebug.println( getRes().getString( "    Size: {0}", new Integer( jarSize ) ) );
                   
                    byte[] bytes = md.digest();
                    StringBuffer sb = new StringBuffer();
                    for ( int i = 0; i < bytes.length; i++ )
                    {
                        String val = Integer.toString( bytes[i] & 0xff, 16 ).toLowerCase();
                        if ( val.length() == 1 )
View Full Code Here

      dout.flush();

      MessageDigest md = MessageDigest.getInstance("SHA");
      if (TRACE_UID) System.out.println(dump(bout.toByteArray()));
     
      byte[] hashBytes = md.digest(bout.toByteArray());
      long hash = 0;
      for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
    hash = (hash << 8) | (hashBytes[i] & 0xFF);
      }
      return hash;
View Full Code Here

  try
  {
   //*-- create a message digest instance and compute the hash byte array
   MessageDigest md = MessageDigest.getInstance("SHA-1");
   md.reset(); md.update(in.getBytes());
   byte[] hash = md.digest();

   //*--- Convert the hash byte array to hexadecimal format, pad hex chars with leading zeroes
   //*--- to get a signature of consistent length (40) for all strings.
   for (int i = 0; i < hash.length; i++)
   { out.append( fillin(Integer.toString(0xFF & hash[i], 16), 2, false, '0', 1) ); }
View Full Code Here

                int chunk = 1024;
                int bytesRead = 0;
                while ((bytesRead = bis.read(buff, 0, chunk)) != -1) {
                    md.update(buff, 0, bytesRead);
                }
                digest = md.digest();
                String hexChar = null;
                if (digest != null) {
                    for (int i = 0; i < digest.length; i++) {
                        if (digest[i] > 0) {
                            hexChar = Integer.toHexString(digest[i]);
View Full Code Here

    // call the update method one or more times
    // (useful when you don't know the size of your data, eg. stream)
    md.update(unencodedPassword);

    // now calculate the hash
    byte[] encodedPassword = md.digest();

    StringBuilder buf = new StringBuilder();

    for (int i = 0; i < encodedPassword.length; i++) {
      if ((encodedPassword[i] & 0xff) < 0x10) {
View Full Code Here

            try
            {
                MessageDigest md = MessageDigest.getInstance("SHA1");
                md.update(certificate.getEncoded());
                String sha1String = getHex(md.digest());

                md = MessageDigest.getInstance("MD5");
                md.update(certificate.getEncoded());
                String md5String = getHex(md.digest());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.