Secure Hash algorithm SHA (Secure hash Algorithm,sha)
The idea of the algorithm is to receive a piece of plaintext, and then convert it into a paragraph (usually smaller) ciphertext in an irreversible way, or simply to take a string of input codes (called Pre-mapping or information) and convert them to shorter lengths, A fixed number of bits of output sequence is the process of hashing values (also known as information digests or information authentication codes).
sha-1,sha-224,sha-256,sha-384, and SHA-512 are some of the one-way hashing algorithms.
sha-1,sha-224 and SHA-256 are suitable for messages that do not exceed 2^64 bits in length.
SHA-384 and SHA-512 are suitable for messages that do not exceed 2^128 bits in length.
package com.soap.util;import java.security.messagedigest;/** * Secure Hash Algorithm sha (Secure Hash algorithm,sha) * * @author roger */public class shautil {/** * sha encryption Generate 40-bit SHA code * * @param string to encrypt * * @return Return 40-bit SHA code */public static string shaencode (STRING&NBSP;INSTR) throws Exception {messagedigest sha = null;try {sha = messagedigest.getinstance (" SHA ");} catch (exception e) {system.out.println (e.tostring ()) e.printstacktrace ();return "";} Byte[] bytearray = instr.getbytes ("UTF-8"); Byte[] md5bytes = sha.digest ( ByteArray); Stringbuffer hexvalue = new stringbuffer ();for (int i = 0; i < md5bytes.length; i++) {int val = ((int) md5bytes[i]) & 0xff;if&nbSP; (val < 16) {hexvalue.append ("0");} Hexvalue.append (Integer.tohexstring (Val));} Return hexvalue.tostring ();} /** * Test main functions * * @param args * @throws exception */ Public static void main (string args[]) throws exception {string str = new string ("123456"); System.out.println ("SHA" + shaencode (str));}}
Java basic encryption of SHA encryption