Created
April 2, 2017 00:58
-
-
Save arnoldmartinez/f48d94d33e91b63ea58deee5f142492a to your computer and use it in GitHub Desktop.
Algorithm for computing SHA-256
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
import javax.xml.bind.DatatypeConverter; | |
/** | |
* @author ARNOLD | |
* | |
*/ | |
public class Algorithm { | |
private transient String sha; | |
private static final String SHA_256; | |
static { | |
SHA_256 = "SHA-256"; | |
} | |
/** | |
* @param message | |
* @return String | |
*/ | |
public String generateSha(String message) { | |
try { | |
sha = getHash(message); | |
} catch (NoSuchAlgorithmException noSuchAlgorithmException) { | |
noSuchAlgorithmException.printStackTrace(); | |
} | |
return sha; | |
} | |
/** | |
* @param sha | |
* @return String | |
*/ | |
private String getHash(String sha) throws NoSuchAlgorithmException { | |
MessageDigest engine = MessageDigest.getInstance(SHA_256); | |
engine.update(sha.getBytes()); | |
byte[] cyphered = engine.digest(); | |
return DatatypeConverter.printHexBinary(cyphered); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've used the bcprov-jdk15on-1.50 jar
here is the link
https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on/1.50