Java SHA256 digestSha256(String value)

Here you can find the source of digestSha256(String value)

Description

Parses a string and returns a SHA-256 checksum of it.

License

Open Source License

Parameter

Parameter Description
value The source string to parse.

Return

A checksum of the source string.

Declaration

public static byte[] digestSha256(String value) 

Method Source Code

//package com.java2s;
/*//  www . j  av  a 2  s  .c  o m
 // This software is subject to the terms of the Eclipse Public License v1.0
 // Agreement, available at the following URL:
 // http://www.eclipse.org/legal/epl-v10.html.
 // You must accept the terms of that agreement to use this software.
 //
 // Copyright (C) 2001-2005 Julian Hyde
 // Copyright (C) 2005-2012 Pentaho and others
 // All Rights Reserved.
 */

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

public class Main {
    /**
     * Parses a string and returns a SHA-256 checksum of it.
     *
     * @param value The source string to parse.
     * @return A checksum of the source string.
     */
    public static byte[] digestSha256(String value) {
        final MessageDigest algorithm;
        try {
            algorithm = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        return algorithm.digest(value.getBytes());
    }
}

Related

  1. digestSHA256(byte[] input)
  2. digestSha256(String plain)
  3. getSHA256(String input)
  4. sha256()
  5. sha256(byte[] bytes)
  6. sha256(byte[] data)