Package java.security

Examples of java.security.MessageDigest


         serverHash.update(M1);
         // serverHash = A | M | K
         serverHash.update(K);
         if( log.isTraceEnabled() )
         {
            MessageDigest tmp = CryptoUtil.copy(serverHash);
            log.trace("H(A | M1 | K)"+CryptoUtil.tob64(tmp.digest()));
         }
         valid = true;
      }
      return valid;
   }
View Full Code Here


      if( log.isTraceEnabled() )
         log.trace("H(N) xor H(g): "+CryptoUtil.tob64(hxg));
      clientHash.update(hxg);
      if( log.isTraceEnabled() )
      {
         MessageDigest tmp = CryptoUtil.copy(clientHash);
         log.trace("H[H(N) xor H(g)]: "+CryptoUtil.tob64(tmp.digest()));
      }
      // clientHash = H(N) xor H(g) | H(U)
      clientHash.update(CryptoUtil.newDigest().digest(username.getBytes()));
      if( log.isTraceEnabled() )
      {
         MessageDigest tmp = CryptoUtil.copy(clientHash);
         log.trace("H[H(N) xor H(g) | H(U)]: "+CryptoUtil.tob64(tmp.digest()));
      }
      // clientHash = H(N) xor H(g) | H(U) | s
      clientHash.update(params.s);
      if( log.isTraceEnabled() )
      {
         MessageDigest tmp = CryptoUtil.copy(clientHash);
         log.trace("H[H(N) xor H(g) | H(U) | s]: "+CryptoUtil.tob64(tmp.digest()));
      }
      K = null;
   }
View Full Code Here

         Abytes = CryptoUtil.trim(A.toByteArray());
         // clientHash = H(N) xor H(g) | H(U) | A
         clientHash.update(Abytes);
         if( log.isTraceEnabled() )
         {
            MessageDigest tmp = CryptoUtil.copy(clientHash);
            log.trace("H[H(N) xor H(g) | H(U) | s | A]: "+CryptoUtil.tob64(tmp.digest()));
         }
         // serverHash = A
         serverHash.update(Abytes);
      }
      return Abytes;
View Full Code Here

   {
      // clientHash = H(N) xor H(g) | H(U) | s | A | B
      clientHash.update(Bbytes);
      if( log.isTraceEnabled() )
      {
         MessageDigest tmp = CryptoUtil.copy(clientHash);
         log.trace("H[H(N) xor H(g) | H(U) | s | A | B]: "+CryptoUtil.tob64(tmp.digest()));
      }
      // Calculate u as the first 32 bits of H(B)
      byte[] hB = CryptoUtil.newDigest().digest(Bbytes);
      byte[] ub =
      {hB[0], hB[1], hB[2], hB[3]};
      // Calculate S = (B - g^x) ^ (a + u * x) % N
      BigInteger B = new BigInteger(1, Bbytes);
      if( log.isTraceEnabled() )
         log.trace("B: "+CryptoUtil.tob64(B.toByteArray()));
      if( B.compareTo(v) < 0 )
         B = B.add(N);
      if( log.isTraceEnabled() )
         log.trace("B': "+CryptoUtil.tob64(B.toByteArray()));
      if( log.isTraceEnabled() )
         log.trace("v: "+CryptoUtil.tob64(v.toByteArray()));
      BigInteger u = new BigInteger(1, ub);
      if( log.isTraceEnabled() )
         log.trace("u: "+CryptoUtil.tob64(u.toByteArray()));
      BigInteger B_v = B.subtract(v);
      if( log.isTraceEnabled() )
         log.trace("B - v: "+CryptoUtil.tob64(B_v.toByteArray()));
      BigInteger a_ux = a.add(u.multiply(x));
      if( log.isTraceEnabled() )
         log.trace("a + u * x: "+CryptoUtil.tob64(a_ux.toByteArray()));
      BigInteger S = B_v.modPow(a_ux, N);
      if( log.isTraceEnabled() )
         log.trace("S: "+CryptoUtil.tob64(S.toByteArray()));
      // K = SessionHash(S)
      MessageDigest sessionDigest = MessageDigest.getInstance(params.hashAlgorithm);
      K = sessionDigest.digest(S.toByteArray());
      if( log.isTraceEnabled() )
         log.trace("K: "+CryptoUtil.tob64(K));
      // clientHash = H(N) xor H(g) | H(U) | A | B | K
      clientHash.update(K);
      byte[] M1 = clientHash.digest();
      if( log.isTraceEnabled() )
         log.trace("M1: H[H(N) xor H(g) | H(U) | s | A | B | K]: "+CryptoUtil.tob64(M1));
      serverHash.update(M1);
      serverHash.update(K);
      if( log.isTraceEnabled() )
      {
         MessageDigest tmp = CryptoUtil.copy(serverHash);
         log.trace("H[A | M1 | K]: "+CryptoUtil.tob64(tmp.digest()));
      }
      return M1;
   }
View Full Code Here

     * @return the encrypted password, or null if encryption failed.
     */
    private String encryptPassword( String password ) {

        try {
            MessageDigest md = MessageDigest.getInstance("SHA");

            //Create the encrypted Byte[]
            md.update( password.getBytes() );
            byte[] hash = md.digest();

            //Convert the byte array into a String

            StringBuffer hashStringBuf = new StringBuffer();
            String byteString;
View Full Code Here

   public static long createHash(String methodDesc)
           throws Exception
   {
      long hash = 0;
      ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(512);
      MessageDigest messagedigest = MessageDigest.getInstance("SHA");
      DataOutputStream dataoutputstream = new DataOutputStream(new DigestOutputStream(bytearrayoutputstream, messagedigest));
      dataoutputstream.writeUTF(methodDesc);
      dataoutputstream.flush();
      byte abyte0[] = messagedigest.digest();
      for (int j = 0; j < Math.min(8, abyte0.length); j++)
         hash += (long) (abyte0[j] & 0xff) << j * 8;
      return hash;

   }
View Full Code Here

  }

  public static String hash(String string, String algorithm, String encoding) throws UnsupportedEncodingException{

    try {
      MessageDigest digest = MessageDigest.getInstance(algorithm);

      digest.update(string.getBytes(encoding));

      byte[] encodedPassword = digest.digest();

      return new BigInteger(1, encodedPassword).toString(16);

      //TODO fix if hash starts with zeroes!
View Full Code Here

  public static String hash(File file, String algorithm, ProgressMeter progressMeter) throws IOException{

    FileInputStream fileInputStream = null;

    try {
      MessageDigest digest = MessageDigest.getInstance(algorithm);
      fileInputStream = new FileInputStream(file);

      DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, digest);

      if(progressMeter != null){

        progressMeter.setStartTime();
        progressMeter.setFinish(file.length());
      }

      byte[] buffer = new byte[8192];

      int bytesRead = 1;

      if(progressMeter != null){

        while ((bytesRead = digestInputStream.read(buffer)) != -1){

          progressMeter.incrementCurrentPosition(bytesRead);
        }

      }else{

        while ((bytesRead = digestInputStream.read(buffer)) != -1){}
      }

      byte[] hash = digest.digest();

      if(progressMeter != null){

        progressMeter.setEndTime();
      }
View Full Code Here

  }

  public static String mysqlPasswordHash(String string){

    try {
      MessageDigest digest = MessageDigest.getInstance(HashAlgorithms.SHA1);

      try {
        digest.update(string.getBytes("UTF-8"));

      } catch (UnsupportedEncodingException e) {

        throw new RuntimeException(e);
      }

      byte[] encodedPassword = digest.digest();

      digest.update(encodedPassword);

      encodedPassword = digest.digest();

      String hash = new BigInteger(1, encodedPassword).toString(16).toUpperCase();

      while(hash.length() < 40){
View Full Code Here

        StringBuffer etag = new StringBuffer();
        etag.append('"');

        /* Append the MD5 hash of this resource name */
        try {
            MessageDigest digester = MessageDigest.getInstance("MD5");
            digester.reset();
            digester.update(path.getBytes("UTF8"));
            etag.append(DAVUtilities.toHexString(digester.digest()));
            etag.append('-');
        } catch (Exception e) {
            // If we can't get the MD5 HASH, let's ignore and hope...
        }

View Full Code Here

TOP

Related Classes of java.security.MessageDigest

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.