Package java.security

Examples of java.security.MessageDigest.reset()


      MessageDigest messageDigest = THREAD_LOCAL_SHA1.get();
      if (messageDigest == null) {
        messageDigest = getSha1();
        THREAD_LOCAL_SHA1.set(messageDigest);
      } else {
        messageDigest.reset();
      }
      return messageDigest;
    } else {
      return getSha1();
    }
View Full Code Here


        MessageDigest messageDigest = null
 
        try
            messageDigest = MessageDigest.getInstance("MD5")
 
            messageDigest.reset()
 
            messageDigest.update(str.getBytes("UTF-8"))
        } catch (NoSuchAlgorithmException e) { 
            System.out.println("NoSuchAlgorithmException caught!")
            System.exit(-1)
View Full Code Here

  public static String getEncryptedPassword(String strPasswordToBeEncrypted) {
    System.out.println(strPasswordToBeEncrypted);
    byte[] defaultBytes = strPasswordToBeEncrypted.getBytes();
    try {
      MessageDigest algorithm = MessageDigest.getInstance("MD5");
      algorithm.reset();
      algorithm.update(defaultBytes);
      byte messageDigest[] = algorithm.digest();

      StringBuffer hexString = new StringBuffer();
      for (int iCounter = 0; iCounter < messageDigest.length; iCounter++) {
View Full Code Here

   * @throws UnsupportedEncodingException
   */
  public String hash(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
  MessageDigest digest = MessageDigest.getInstance("SHA-1");
  byte[] input = digest.digest(str.getBytes("UTF-8"));
  digest.reset();
  byte[] enc = digest.digest(input);
  return com.google.appengine.repackaged.com.google.common.util.Base64.encode(enc);
  }

  /**
 
View Full Code Here

    public void testUsernameTokenDigestText() throws Exception {
        WSSecUsernameToken builder = new WSSecUsernameToken();
        builder.setPasswordType(WSConstants.PASSWORD_TEXT);
        byte[] password = "verySecret".getBytes();
        MessageDigest sha = MessageDigest.getInstance("MD5");
        sha.reset();
        sha.update(password);
        String passwdDigest = Base64.encode(sha.digest());
       
        builder.setUserInfo("wernerd", passwdDigest);
        LOG.info("Before adding UsernameToken PW Text....");
View Full Code Here

   
    private String getSHA1(byte[] input) {
        MessageDigest sha;
        try {
            sha = MessageDigest.getInstance("SHA-1");
            sha.reset();
            sha.update(input);
            byte[] data = sha.digest();
            return Base64.encode(data);
        } catch (NoSuchAlgorithmException e) {
            //REVISIT
View Full Code Here

            alg = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException ex) {
            // this should never happen
            throw new MathInternalError(ex);
        }
        alg.reset();

        // Compute number of iterations required (40 bytes each)
        int numIter = (len / 40) + 1;

        StringBuilder outBuffer = new StringBuilder();
View Full Code Here

        } while (bytesRead != -1);
        in.close();

        /* Compute the checksum with the digest */
        byte[] byteChecksum = digest.digest();
        digest.reset();

        return toHexString(byteChecksum);
    }

    /**
 
View Full Code Here

    }

    public static String getMD5(String plaintext) throws NoSuchAlgorithmException
    {
      MessageDigest m = MessageDigest.getInstance("MD5");
      m.reset();
      m.update(plaintext.getBytes());
      byte[] digest = m.digest();
      BigInteger bigInt = new BigInteger(1, digest);
      String hashtext = bigInt.toString(16);
View Full Code Here

        InputStream stream = null;
        try {
            stream = new FileInputStream(file);
           
            MessageDigest digester = MessageDigest.getInstance(algorithm);
            digester.reset();

            byte buf[] = new byte[4096];
            int len = 0;

            while ((len = stream.read(buf, 0, 1024)) != -1) {
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.