Java SHA1 digestSHA1(String login, String pass)

Here you can find the source of digestSHA1(String login, String pass)

Description

digest SHA

License

Apache License

Declaration

public static String digestSHA1(String login, String pass) throws NoSuchAlgorithmException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static final String hexDigits = "0123456789abcdef";

    public static String digestSHA1(String login, String pass) throws NoSuchAlgorithmException {
        String input = login + pass;
        return byteArrayToHexString(digest(input.getBytes(), "SHA-1"));
    }//from  www  .j  a  v  a  2s  . com

    public static String byteArrayToHexString(byte[] b) {
        StringBuffer buf = new StringBuffer();

        for (int i = 0; i < b.length; i++) {
            int j = ((int) b[i]) & 0xFF;
            buf.append(hexDigits.charAt(j / 16));
            buf.append(hexDigits.charAt(j % 16));
        }

        return buf.toString();
    }

    public static byte[] digest(byte[] input, String algoritmo) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance(algoritmo);
        md.reset();
        return md.digest(input);
    }
}

Related

  1. computeSha1(ReadableByteChannel channel)
  2. computeSha1AsHexString(String strToHash)
  3. computeSHA1Hash(byte[] data)
  4. digestSHA1(byte[] data)
  5. digestSHA1(String data)
  6. digestSHA1(String text)
  7. digestSha1Hex(String source)
  8. doSHA1(byte[] buf)
  9. doSHA1(byte[] buf, int off, int len)