Examples of MessageDigest


Examples of java.security.MessageDigest

    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

Examples of java.security.MessageDigest

     *      href="http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-stubs24.html">Method
     *      hashing of RMI</a>
     */
    public static long hashMethod(final String methodName, final String methodDescriptor) {

        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("Algorithm SHA-1 is not available", e);
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DigestOutputStream dos = new DigestOutputStream(baos, md);
        DataOutputStream das = new DataOutputStream(dos);

        StringBuilder sb = new StringBuilder();
        sb.append(methodName);
        sb.append(methodDescriptor);
        try {
            das.writeUTF(sb.toString());
        } catch (IOException e) {
            throw new IllegalStateException("Cannot write data for method '" + methodName + "'.", e);
        }
        try {
            das.flush();
        } catch (IOException e) {
            logger.warn("Cannot flush the stream", e);
        }
        try {
            das.close();
        } catch (IOException e) {
            logger.warn("Cannot flush the stream", e);
        }

        byte[] digest = md.digest();
        long hash = 0;
        int size = Math.min(digest.length, BYTES_LENGTH);
        for (int i = 0; i < size; i++) {
            hash += (long) (digest[i] & BYTE_MASK) << (BYTES_LENGTH * i);
        }
View Full Code Here

Examples of java.security.MessageDigest

     */
    public DESCrypt(String password) {
        try {

            // Generate the key by taking the MD5 of the password
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Key = md5.digest(password.getBytes("UTF-8"));

            // Generate the key by compressing 8 bytes to 7
            byte[] inKey = new byte[8];
            inKey[0] = md5Key[0];
            inKey[1] = (byte) (((md5Key[0] & 0xFF) << 7) |
View Full Code Here

Examples of java.security.MessageDigest

     * @param password
     *            The encryption password
     */
    public AESCrypt(String password) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Key = md5.digest(password.getBytes("UTF-8"));

            SecretKeySpec secretKey = new SecretKeySpec(md5Key, "AES");

            decrypter = Cipher.getInstance("AES/ECB/NoPadding");
            encrypter = Cipher.getInstance("AES/ECB/NoPadding");
View Full Code Here

Examples of java.security.MessageDigest

        return hash(plaintext.toCharArray());
    }

    public static String hash(char[] plaintext){
        try {
            MessageDigest sha = MessageDigest.getInstance(hashAlgorithm);
            byte[] hash = sha.digest(charArrayToByteArray(plaintext));
            return byteArrayToHexString(hash);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of java.security.MessageDigest

            {
                InputStream is = jarLocation.openStream();
                try
                {
                    int jarSize = 0;
                    MessageDigest md = MessageDigest.getInstance( "MD5" );
                    int data;
                    while ( ( data = is.read() ) >= 0 )
                    {
                        jarSize++;
                        md.update( (byte)( data & 0xff ) );
                    }
                    m_outDebug.println( getRes().getString( "    Size: {0}", new Integer( jarSize ) ) );
                   
                    byte[] bytes = md.digest();
                    StringBuffer sb = new StringBuffer();
                    for ( int i = 0; i < bytes.length; i++ )
                    {
                        String val = Integer.toString( bytes[i] & 0xff, 16 ).toLowerCase();
                        if ( val.length() == 1 )
View Full Code Here

Examples of java.security.MessageDigest

    }
      }

      dout.flush();

      MessageDigest md = MessageDigest.getInstance("SHA");
      if (TRACE_UID) System.out.println(dump(bout.toByteArray()));
     
      byte[] hashBytes = md.digest(bout.toByteArray());
      long hash = 0;
      for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) {
    hash = (hash << 8) | (hashBytes[i] & 0xFF);
      }
      return hash;
View Full Code Here

Examples of java.security.MessageDigest

{
  StringBuffer out = new StringBuffer();
  try
  {
   //*-- create a message digest instance and compute the hash byte array
   MessageDigest md = MessageDigest.getInstance("SHA-1");
   md.reset(); md.update(in.getBytes());
   byte[] hash = md.digest();

   //*--- Convert the hash byte array to hexadecimal format, pad hex chars with leading zeroes
   //*--- to get a signature of consistent length (40) for all strings.
   for (int i = 0; i < hash.length; i++)
   { out.append( fillin(Integer.toString(0xFF & hash[i], 16), 2, false, '0', 1) ); }
View Full Code Here

Examples of java.security.MessageDigest

         */
        public String createMD5Sum() {
            String out = "";
            try {
                byte[] digest;
                MessageDigest md = MessageDigest.getInstance("MD5");
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fFile));
                byte[] buff = new byte[1024];
                int chunk = 1024;
                int bytesRead = 0;
                while ((bytesRead = bis.read(buff, 0, chunk)) != -1) {
                    md.update(buff, 0, bytesRead);
                }
                digest = md.digest();
                String hexChar = null;
                if (digest != null) {
                    for (int i = 0; i < digest.length; i++) {
                        if (digest[i] > 0) {
                            hexChar = Integer.toHexString(digest[i]);
View Full Code Here

Examples of java.security.MessageDigest

   * @return encypted password based on the algorithm.
   */
  public static String encode(String password, String algorithm) {
    byte[] unencodedPassword = password.getBytes();

    MessageDigest md = null;

    try {
      // first create an instance, given the provider
      md = MessageDigest.getInstance(algorithm);
    } catch (Exception e) {
      logger.error("Exception:{}", e);
      return password;
    }

    md.reset();

    // call the update method one or more times
    // (useful when you don't know the size of your data, eg. stream)
    md.update(unencodedPassword);

    // now calculate the hash
    byte[] encodedPassword = md.digest();

    StringBuilder buf = new StringBuilder();

    for (int i = 0; i < encodedPassword.length; i++) {
      if ((encodedPassword[i] & 0xff) < 0x10) {
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.