Java SHA1 sha1AsBytes(String input)

Here you can find the source of sha1AsBytes(String input)

Description

sha As Bytes

License

Apache License

Declaration

public static byte[] sha1AsBytes(String input) 

Method Source Code


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

import java.nio.charset.StandardCharsets;

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

public class Main {
    public static byte[] sha1AsBytes(String input) {
        return sha1AsBytes(input.getBytes(StandardCharsets.UTF_8));
    }/*from  w  w w .ja va  2  s  .com*/

    /**
     * Generate SHA-1 as bytes.
     *
     * @param input Input as bytes.
     * @return Bytes.
     */
    public static byte[] sha1AsBytes(byte[] input) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        md.update(input);
        return md.digest();
    }
}

Related

  1. sha1(String value)
  2. sha1(String value)
  3. sha12String(MessageDigest messageDigest)
  4. sha1_b64(final String text)
  5. SHA1_HEX(byte[] bytes)
  6. sha1ByString(String str)
  7. SHA1Checksum(String filename)
  8. sha1Digest(byte[] bytes)
  9. sha1Digest(byte[] bytes)