Package java.security

Examples of java.security.MessageDigest


        final String signature = buffer.toString();

        String serialVersionUID = String.valueOf(0L);
        try
        {
            MessageDigest md = MessageDigest.getInstance("SHA");
            byte[] hashBytes = md.digest(signature.getBytes());

            long hash = 0;
            for (int ctr = Math.min(
                        hashBytes.length,
                        8) - 1; ctr >= 0; ctr--)
View Full Code Here


  private static final char[] hexChars = { '0', '1', '2', '3', '4', '5', '6',
      '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

  public static String MD5(String str) {
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(str.getBytes());
      return hexStringFromBytes(md.digest());
    } catch (Exception e) {
      e.printStackTrace();
      return "";
    }
  }
View Full Code Here

    }
  }

  public static String MD5(byte[] source) {
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(source);
      return hexStringFromBytes(md.digest());
    } catch (Exception e) {
      e.printStackTrace();
      return "";
    }
  }
View Full Code Here

    }
  }

  public static byte[] MD5bytes(String str) {
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(str.getBytes());
      return md.digest();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
View Full Code Here

        else {
            out.println("  " + url);
            try {
                final String algorithm = "MD5";
                byte[] digest;
                MessageDigest md = MessageDigest.getInstance(algorithm);
                DigestInputStream in = new DigestInputStream(url.openStream(), md);
                try {
                    byte[] buf = new byte[8192];
                    int n;
                    do { n = in.read(buf); } while (n > 0);
                    digest = md.digest();
                } finally {
                    in.close();
                }
                StringBuilder sb = new StringBuilder();
                for (byte b: digest)
View Full Code Here

  /** */
  private boolean checkIntegrity(File src, File dest) throws IOException, NoSuchAlgorithmException
  {
    BufferedInputStream ins = new BufferedInputStream(new FileInputStream(src));
    BufferedInputStream ind = new BufferedInputStream(new FileInputStream(dest));
    MessageDigest md1 = MessageDigest.getInstance("MD5");
    MessageDigest md2 = MessageDigest.getInstance("MD5");

    int r = 0;
    byte[] buf1 = new byte[BUFFER_SIZE];
    byte[] buf2 = new byte[BUFFER_SIZE];

    while (r !=-1)
    {
      r = ins.read(buf1);
      ind.read(buf2);

      md1.update(buf1);
      md2.update(buf2);
    }

    ins.close();
    ind.close();
    return MessageDigest.isEqual(md1.digest(), md2.digest());
  }
View Full Code Here

    testDigest();
  }

  static private void testDigest() {
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      Provider p = md.getProvider();
      Set<Provider.Service> services = p.getServices();
      for (Provider.Service service : services) {
        System.out.println("Service="+service);
      }
    } catch (NoSuchAlgorithmException e) {
View Full Code Here

   The static initializer of this class will barf if the hash function is not present.
  */
  private static String hash(String aCleartext) {
    String result = null;
   
    MessageDigest sha = null;
    try {
      sha = MessageDigest.getInstance("SHA-1");
    }
    catch (NoSuchAlgorithmException ex){
      fLogger.severe("Cannot find SHA-1 hash function.");
    }

    if (sha != null){
      byte[] digest =  sha.digest( aCleartext.getBytes() );
      result = hexEncode(digest);
    }
    else {
      result = aCleartext;
    }
View Full Code Here

    return shift(minId(valueOf(value)));
  }

  public long hashOf(Value value) {
    final long span = 1152921504606846975l;
    MessageDigest digest = md5.get();
    long type = hashLiteralType(digest, value);
    long hash = type * 31 + hash(digest, value.stringValue());
    return hash & span | valueOf(value).index() * (span + 1);
  }
View Full Code Here

    if (algorithmID == null) {
      Object[] exArgs = { algorithmURI };
      throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
    }

      MessageDigest md;
      String provider=JCEMapper.getProviderId();
      try {       
         if (provider==null) {
           md = MessageDigest.getInstance(algorithmID);
         } else {
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.