Java SHA256 SHA256Binary(String toHash)

Here you can find the source of SHA256Binary(String toHash)

Description

This SHA256 function returns a 256-character binary String representing the full SHA256 hash of the String toHash This binary String is useful when signing a message with a Lamport Signature.

License

Open Source License

Parameter

Parameter Description
toHash The String to hash using SHA256

Return

String The binary String representing the entire SHA256 hash of toHash

Declaration

private static String SHA256Binary(String toHash) 

Method Source Code

//package com.java2s;
/*/*from  w ww  .  j av a2 s  . c om*/
 * SigmaX 1.0.0b1 Source Code
 * Copyright (c) 2016 Curecoin Developers
 * Distributed under MIT License
 * Requires Apache Commons Library
 * Supports Java 1.7+
 */

import java.security.*;
import java.math.*;

public class Main {
    private static MessageDigest md;

    /**
     * This SHA256 function returns a 256-character binary String representing the full SHA256 hash of the String toHash
     * This binary String is useful when signing a message with a Lamport Signature.
     * 
     * @param toHash The String to hash using SHA256
     * 
     * @return String The binary String representing the entire SHA256 hash of toHash
     */
    private static String SHA256Binary(String toHash) {
        try {
            byte[] messageHash = md.digest(toHash.getBytes("UTF-8"));
            return new BigInteger(1, messageHash).toString(2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. sha256(String strSrc)
  2. SHA256(String text)
  3. SHA256(String text)
  4. sha256(String text)
  5. SHA256(String texto)
  6. SHA256byte(String input)
  7. sha256digest(@Nonnull byte[] data)
  8. sha256Digest(byte[] bytes)
  9. sha256Digest(final InputStream data)