Package java.security

Examples of java.security.MessageDigest$Delegate


     * @return
     * @throws Exception
     */
    public static String MD5encrypt(String str) throws Exception {

        MessageDigest md = null;
        md = MessageDigest.getInstance("MD5");
        md.reset();
        md.update(str.getBytes());

        return toHexString(md.digest());
    }
View Full Code Here


    public static byte[] createChecksum(File inputFile) throws
    Exception{
      InputStream fis =  new FileInputStream(inputFile);

      byte[] buffer = new byte[1024];
      MessageDigest md = MessageDigest.getInstance("MD5");
      int numRead;
      do {
        numRead = fis.read(buffer);
        if (numRead > 0) {
          md.update(buffer, 0, numRead);
        }
      } while (numRead != -1);
      fis.close();
      return md.digest();
    }
View Full Code Here

    }
    if (objInput == null) {
      RaiseException("virtual source file has null value.");
    }
    boolean flgCreateSecurityHash = objOptions.CreateSecurityHash.value();
    MessageDigest md = null;
    if (flgCreateSecurityHash) {
      try {
        // TODO implement in value-method of securityhashtype
        md = MessageDigest.getInstance(objOptions.SecurityHashType.Value());
      }
      catch (NoSuchAlgorithmException e1) {
        e1.printStackTrace();
        flgCreateSecurityHash = false;
      }
    }
    long lngTotalBytesTransferred = 0;
    this.setStatus(enuTransferStatus.transferring);
    try {
      int lngBufferSize = objOptions.BufferSize.value();
      byte[] buffer = new byte[lngBufferSize];
      int intBytesTransferred;
      synchronized (this) {
        while ((intBytesTransferred = objInput.read(buffer)) != -1) {
          try {
            objOutput.write(buffer, 0, intBytesTransferred);
          }
          catch (JobSchedulerException e) {
            break;
          }
          // TODO in case of wrong outputbuffer tha handling of the error must be improved
          lngTotalBytesTransferred += intBytesTransferred;
          setTransferProgress(lngTotalBytesTransferred);
          if (flgCreateSecurityHash) {
            md.update(buffer, 0, intBytesTransferred);
          }
        }
      }
      objInput.closeInput();
      objOutput.closeOutput();
      flgClosingDone = true;
      if (flgCreateSecurityHash) {
        strMD5Hash = toHexString(md.digest());
        logger.info(String.format("Security hash (%3$s) for file %2$s is %1$s", strMD5Hash, strSourceTransferName, objOptions.SecurityHashType.Value()));
      }
      // objDataTargetClient.CompletePendingCommand();
      if (objDataTargetClient.isNegativeCommandCompletion()) {
        RaiseException("..error occurred during transfer on the data-target for file [" + objTargetTransferFile.getName() + "]: "
View Full Code Here

      persitedProperties.setStringProperty(CONF_KEY_REGISTRATION_CRON, cronExpression, true);
    }
    // Check if instance identifyer property exists
    if (persitedProperties.getStringPropertyValue(CONF_KEY_IDENTIFYER, false) == null) {
      String uniqueID = CodeHelper.getGlobalForeverUniqueID();
      MessageDigest digester;
      try {
        digester = MessageDigest.getInstance("MD5");
        digester.update(uniqueID.getBytes(),0,uniqueID.length());
        persitedProperties.setStringProperty(CONF_KEY_IDENTIFYER, new BigInteger(1,digester.digest()).toString(16), true);
        // trigger first execution of registration
//FIXME:FG:6.1: deferre this execution until framework is fully loaded
        //sendRegistrationData();
      } catch (NoSuchAlgorithmException e) {
        // using no encoding instead
View Full Code Here

                    throw new IOException(
                        "Incompatible protocol version " + protocolVersion +
                        ". At most 220 was expected.");
                }
                byte[] challenge = (byte[])in.readObject();
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(password.getBytes("UTF-8"));
                md.update(challenge);
                out.writeObject(md.digest());
                return new LocalDebuggerProxy((Debugger)in.readObject());
                //return (Debugger)in.readObject();
            }
            finally
            {
View Full Code Here

  /**
   Return text of fixed length, representing a hash of a cleartext password.
   */
  public static String hash(String aCleartextPassword){
    String result = null;
    MessageDigest sha = null;
    try {
      sha = MessageDigest.getInstance("SHA-1");
    }
    catch (NoSuchAlgorithmException ex){
      throw new RuntimeException("Cannot find SHA-1 hash function.");
    }
    //the salt is not included here - see class comment
    String clearTextPlusSalt = aCleartextPassword /* + SALT*/;
    byte[] digest =  sha.digest( clearTextPlusSalt.getBytes() );
    result = hexEncode(digest);
    return result;
  }
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

    {
        XMLStreamWriter2 sw = (XMLStreamWriter2) _xmlOutputFactory.createXMLStreamWriter(out);
        sw.writeStartDocument();
        sw.writeStartElement("files");
        byte[] buffer = new byte[4000];
        MessageDigest md;
        try {
            md = MessageDigest.getInstance(DIGEST_TYPE);
        } catch (Exception e) { // no such hash type?
            throw new IOException(e);
        }

        for (File f : _downloadableFiles.listFiles()) {
            sw.writeStartElement("file");
            sw.writeAttribute("name", f.getName());
            sw.writeAttribute("checksumType", DIGEST_TYPE);
            FileInputStream fis = new FileInputStream(f);
            int count;
            while ((count = fis.read(buffer)) != -1) {
                md.update(buffer, 0, count);
                sw.writeBinary(buffer, 0, count);
            }
            fis.close();
            sw.writeEndElement(); // file
            sw.writeStartElement("checksum");
            sw.writeBinaryAttribute("", "", "value", md.digest());
            sw.writeEndElement(); // checksum
        }
        sw.writeEndElement(); // files
        sw.writeEndDocument();
        sw.close();
View Full Code Here

            String filename = sr.getAttributeValue("", "name");
            String csumType = sr.getAttributeValue("", "checksumType");
            File outputFile = new File(toDir, filename);
            FileOutputStream out = new FileOutputStream(outputFile);
            files.add(outputFile);
            MessageDigest md = MessageDigest.getInstance(csumType);
           
            int count;
            // Read binary contents of the file, calc checksum and write
            while ((count = sr.readElementAsBinary(buffer, 0, buffer.length)) != -1) {
                md.update(buffer, 0, count);
                out.write(buffer, 0, count);
            }
            out.close();
            // Then verify checksum
            sr.nextTag()
            byte[] expectedCsum = sr.getAttributeAsBinary(sr.getAttributeIndex("", "value"));
            byte[] actualCsum = md.digest();
            if (!Arrays.equals(expectedCsum, actualCsum)) {
                throw new IllegalArgumentException("File '"+filename+"' corrupt: content checksum does not match expected");
            }
            sr.nextTag(); // to match closing "checksum"
        }
View Full Code Here

/* This string is magic for this algorithm.  Having it this way,
  * we can get get better later on */

String magic = "$1$";
byte finalState[];
MessageDigest ctx, ctx1;
long l;

/* -- */

/* Refine the Salt first */

/* If it starts with the magic string, then skip that */
if (salt.startsWith(magic))
   {
  salt = salt.substring(magic.length());
   }

/* It stops at the first '$', max 8 chars */

if (salt.indexOf('$') != -1)
   {
  salt = salt.substring(0, salt.indexOf('$'));
   }

if (salt.length() > 8)
   {
  salt = salt.substring(0, 8);
   }

ctx = MessageDigest.getInstance("MD5");

ctx.update(password.getBytes());    // The password first, since that is what is most unknown
ctx.update(magic.getBytes());    // Then our magic string
ctx.update(salt.getBytes());    // Then the raw salt

/* Then just as many characters of the MD5(pw,salt,pw) */

ctx1 = MessageDigest.getInstance("MD5");
ctx1.update(password.getBytes());
ctx1.update(salt.getBytes());
ctx1.update(password.getBytes());
finalState = ctx1.digest();

for (int pl = password.length(); pl > 0; pl -= 16)
   {
  for( int i=0; i< (pl > 16 ? 16 : pl); i++ )
    ctx.update(finalState[i] );
   }

/* the original code claimed that finalState was being cleared
    to keep dangerous bits out of memory, but doing this is also
    required in order to get the right output. */

clearbits(finalState);
/* Then something really weird... */

for (int i = password.length(); i != 0; i >>>=1)
   {
  if ((i & 1) != 0)
    {
      ctx.update(finalState[0]);
    }
  else
    {
      ctx.update(password.getBytes()[0]);
    }
   }

finalState = ctx.digest();

/*
  * and now, just to make sure things don't run too fast
  * On a 60 Mhz Pentium this takes 34 msec, so you would
  * need 30 seconds to build a 1000 entry dictionary...
View Full Code Here

TOP

Related Classes of java.security.MessageDigest$Delegate

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.