Java SHA SHAsum(byte[] convertme)

Here you can find the source of SHAsum(byte[] convertme)

Description

SH Asum

License

Apache License

Declaration

public static String SHAsum(byte[] convertme) 

Method Source Code


//package com.java2s;
/*/*  ww w.j  a va 2  s . c  o  m*/
 * Copyright 2014 scape.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;

public class Main {
    public static String SHAsum(byte[] convertme) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            return "sha1:" + byteArray2Hex(md.digest(convertme));
        } catch (NoSuchAlgorithmException e) {
            return "";
        }
    }

    private static String byteArray2Hex(final byte[] hash) {
        Formatter formatter = new Formatter();
        for (byte b : hash) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    }
}

Related

  1. SHA_1(byte[] input)
  2. shaFile(String paramString)
  3. SHAHash(byte[] input)
  4. shaHash(String message)
  5. shaPsw(String inputText)
  6. SHAsum(byte[] convertme, boolean prefix, boolean uppercase)
  7. SHAsum(byte[] input)