Skip to content

Instantly share code, notes, and snippets.

@DinoChiesa
Created December 21, 2015 07:04
Show Gist options
  • Save DinoChiesa/505be4116258c007cbc8 to your computer and use it in GitHub Desktop.
Save DinoChiesa/505be4116258c007cbc8 to your computer and use it in GitHub Desktop.
Compute SHA-256 in Java
import java.security.MessageDigest;
import org.apache.commons.codec.binary.Base64;
...
MessageDigest md = MessageDigest.getInstance("SHA256");
byte[] hashBytes = md.digest(stringToHash.getBytes("UTF-8"));
String hashB64 = Base64.encodeBase64String(hashBytes);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment