Package java.security

Examples of java.security.MessageDigest$MessageDigestImpl


 
  public static void runTests() {
    try {
   
      //SHA1 sha1Jmule = new SHA1();
      MessageDigest sha1Sun = MessageDigest.getInstance("SHA-1");
      SHA1 sha1Gudy = new SHA1();
      //SHA1Az shaGudyResume = new SHA1Az();
   
      ByteBuffer buffer = ByteBuffer.allocate( 1024 * 1024 );
   
      File dir = new File( dirname );
      File[] files = dir.listFiles();

      for (int i=0; i < files.length; i++) {
        FileChannel fc = new RandomAccessFile( files[i], "r" ).getChannel();
       
        System.out.println("Testing " + files[i].getName() + " ...");
       
        while( fc.position() < fc.size() ) {
         fc.read( buffer );
         buffer.flip();
        
         byte[] raw = new byte[ buffer.limit() ];
         System.arraycopy( buffer.array(), 0, raw, 0, raw.length );

         sha1Gudy.update( buffer );
         sha1Gudy.saveState();
         ByteBuffer bb = ByteBuffer.wrap( new byte[56081] );
         sha1Gudy.digest( bb );
         sha1Gudy.restoreState();
        
         sha1Sun.update( raw );
        
         buffer.clear();
        }
       
        byte[] sun = sha1Sun.digest();
        sha1Sun.reset();
       
        byte[] gudy = sha1Gudy.digest();
        sha1Gudy.reset();
       
        if ( Arrays.equals( sun, gudy ) ) {
View Full Code Here


    int magicLength = do0x0bMagic1(magic);
    do0x0bMagic2(magicLength, magic);
    byte[] magicKeyChar = do0x0bMagic3(magicLength, magic);

    // Get password and crypt hashes as per usual.
    MessageDigest md5 = MessageDigest.getInstance("MD5");
    md5.update(password.getBytes());
    char[] result = Util.byteArrayToCharArray(md5.digest());
    char[] passwordHash = toBase64(result);

    md5.reset();
    byte[] cryptResult = crypt(password, "$1$_2S43d5f$");
    md5.update(cryptResult);
    result = Util.byteArrayToCharArray(md5.digest());
    char[] cryptHash = toBase64(result);

    // Our first authentication response is based off the password hash.
    String resp6 = get0x0bResponseString(passwordHash, magicKeyChar);
    // Our second authentication response is based off the crypto hash.
View Full Code Here

    for (int i = 0; i < 0xffff && !done; i++) {
      for (int j = 0; j < 5 && !done; j++) {
        chal[4] = (byte) i;
        chal[5] = (byte) (i >> 8);
        chal[6] = (byte) j;
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(chal);
        byte[] result = md5.digest();
        if (Arrays.equals(compare, result)) {
          depth = i;
          table = j;
          done = true;
        }
View Full Code Here

    for (x = 0; x < hash.length; x++)
      hashXOR2[cnt++] = (byte) (hash[x] ^ 0x5c);
    for (x = cnt; x < hashXOR2.length; x++)
      hashXOR2[x] = 0x5c;

    MessageDigest sha1 = MessageDigest.getInstance("SHA");
    MessageDigest sha2 = MessageDigest.getInstance("SHA");

    /* The first context gets the password hash XORed with 0x36 plus a magic
     * value which we previously extrapolated from our challenge. */
    sha1.update(hashXOR1);
    sha1.update(magicKeyChar);
    byte[] digest1 = sha1.digest();

    /* The second context gets the password hash XORed
     * with 0x5c plus the SHA-1 digest of the first context. */
    sha2.update(hashXOR2);
    sha2.update(digest1);
    char[] digest2 = Util.byteArrayToCharArray(sha2.digest());

    /* Now that we have digest2, use it to fetch characters from
     * an alphabet to construct our first authentication response. */
    char[] alphabet1 = "FBZDWAGHrJTLMNOPpRSKUVEXYChImkwQ".toCharArray();
    char[] alphabet2 = "F0E1D2C3B4A59687abcdefghijklmnop".toCharArray();
View Full Code Here

    return response.toString();
  }

  private String[] doPre0x0bEncrypt() throws NoSuchAlgorithmException {
    MessageDigest md5 = MessageDigest.getInstance("MD5");

    md5.update(password.getBytes());
    char[] result = Util.byteArrayToCharArray(md5.digest());
    char[] passwordHash = toBase64(result);

    md5.reset();
    byte[] cryptResult = crypt(password, "$1$_2S43d5f$");
    md5.update(cryptResult);
    result = Util.byteArrayToCharArray(md5.digest());
    char[] cryptHash = toBase64(result);

    int sv = seed[15] % 8;
    char checksum = 0;
    String hashStringP = null, hashStringC = null;
    switch (sv % 5) {
      case 0 :
        checksum = (char) (seed[seed[7] % 16] & 0xff);
        hashStringP =
          String.valueOf(checksum)
            + new String(passwordHash)
            + yahooId
            + new String(seed);
        hashStringC =
          String.valueOf(checksum)
            + new String(cryptHash)
            + yahooId
            + new String(seed);
        break;
      case 1 :
        checksum = (char) (seed[seed[9] % 16] & 0xff);
        hashStringP =
          String.valueOf(checksum)
            + yahooId
            + new String(seed)
            + new String(passwordHash);
        hashStringC =
          String.valueOf(checksum)
            + yahooId
            + new String(seed)
            + new String(cryptHash);
        break;
      case 2 :
        checksum = (char) (seed[seed[15] % 16] & 0xff);
        hashStringP =
          String.valueOf(checksum)
            + new String(seed)
            + new String(passwordHash)
            + yahooId;
        hashStringC =
          String.valueOf(checksum)
            + new String(seed)
            + new String(cryptHash)
            + yahooId;
        break;
      case 3 :
        checksum = (char) (seed[seed[1] % 16] & 0xff);
        hashStringP =
          String.valueOf(checksum)
            + yahooId
            + new String(passwordHash)
            + new String(seed);
        hashStringC =
          String.valueOf(checksum)
            + yahooId
            + new String(cryptHash)
            + new String(seed);
        break;
      case 4 :
        checksum = (char) (seed[seed[3] % 16] & 0xff);
        hashStringP =
          String.valueOf(checksum)
            + new String(passwordHash)
            + new String(seed)
            + yahooId;
        hashStringC =
          String.valueOf(checksum)
            + new String(cryptHash)
            + new String(seed)
            + yahooId;
        break;
    }

    md5.reset();
    md5.update(hashStringP.getBytes());
    result = Util.byteArrayToCharArray(md5.digest());
    char[] result6 = toBase64(result);

    md5.reset();
    md5.update(hashStringC.getBytes());
    result = Util.byteArrayToCharArray(md5.digest());
    char[] result96 = toBase64(result);

    String ret[] = new String[2];
    ret[0] = new String(result6);
    ret[1] = new String(result96);
View Full Code Here

      saltLen = salt.length();
    if (saltLen > 8)
      saltLen = 8;

    // Prepare for the real work.
    MessageDigest md1 = MessageDigest.getInstance("MD5");

    // Add the key string.
    md1.update(key.getBytes());

    // Because the SALT argument need not always have the salt prefix we
    // add it separately.
    md1.update(md5SaltPrefix.getBytes());

    // The last part is the salt string.  This must be at most 8
    // characters and it ends at the first `$' character (for
    // compatibility which existing solutions).
    md1.update(salt.getBytes(), 0, saltLen);

    /* Compute alternate MD5 sum with input KEY, SALT, and KEY.  The
    final result will be added to the first context.  */
    MessageDigest md2 = MessageDigest.getInstance("MD5");

    // Add key.
    md2.update(key.getBytes());

    // Add salt.
    md2.update(salt.getBytes(), 0, saltLen);

    // Add key again.
    md2.update(key.getBytes());

    // Now get result of this (16 bytes) and add it to the other context.
    byte[] altResult = md2.digest();

    // Add for any character in the key one byte of the alternate sum.
    int cnt;
    for (cnt = key.length(); cnt > 16; cnt -= 16)
      md1.update(altResult, 0, 16);
View Full Code Here

   * @param str the input string.
   * @return the MD5 hash of the input string.
   */
  static String getMD5Hash(String str) throws NoSuchAlgorithmException
  {
    MessageDigest md = MessageDigest.getInstance("MD5");

    md.update(str.getBytes());

    byte[] b = md.digest();
    StringBuffer sb = new StringBuffer();

    for(int i = 0; i < b.length; i++)
    {
      int v = (int) b[i];
View Full Code Here

     *
     * @param data the byte array
     * @return the SHA1 checksum
     */
    protected static String getSHA1(byte[] data) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
            return convertBytesToString(md.digest(data));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

            sysOut.print(s);
        }
    }

    private static String getSHA1(byte[] data) {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
            return convertBytesToString(md.digest(data));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

            if(!foundRecipient || envelopedData == null)
            {
                throw new IOException("Bad certificate and key.");
            }           

            MessageDigest md = null;

            try {
                md = MessageDigest.getInstance("SHA-1");
                md.update(envelopedData, 0, 20);
                for (int i=0; i<recipients.size(); i++)
                {
                  byte[] encodedRecipient = ((PdfObject)recipients.getArrayList().get(i)).getBytes()
                  md.update(encodedRecipient);
                }
                if ((cryptoMode & PdfWriter.DO_NOT_ENCRYPT_METADATA) != 0)
                    md.update(new byte[]{(byte)255, (byte)255, (byte)255, (byte)255});
                encryptionKey = md.digest();
               
            } catch (Exception f) {
                throw new ExceptionConverter(f);
            }
        }
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.