Java Hash Calculate getHash(String credentials)

Here you can find the source of getHash(String credentials)

Description

get Hash

License

Open Source License

Declaration

public static String getHash(String credentials) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class Main {
    public static String getHash(String credentials) {
        try {/*from   ww  w . j  a v a  2  s . c  o m*/
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.reset();
            byte[] input = digest.digest(credentials.getBytes());
            return byteToBase64(input);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * From a byte[] returns a base 64 representation
     * 
     * @param data
     *            byte[]
     * @return String
     * @throws IOException
     */
    public static String byteToBase64(byte[] data) {
        BASE64Encoder endecoder = new BASE64Encoder();
        return endecoder.encode(data);
    }
}

Related

  1. getHash(final String text, final Charset charset, final MessageDigest algorithm)
  2. getHash(InputStream in, String algorithm)
  3. getHash(InputStream is, String algorithm)
  4. getHash(int iterationNb, String password, byte[] salt)
  5. getHash(String algorithm, int i)
  6. getHash(String Data)
  7. getHash(String fileName, String hashType)
  8. getHash(String givenStr)
  9. getHash(String input)