Last active
August 29, 2015 14:20
-
-
Save ernestoongaro/1a36b95a663b6b0cc54a to your computer and use it in GitHub Desktop.
This file contains 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
package routines; | |
import java.math.BigInteger; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
import sun.misc.BASE64Encoder; | |
public class hashingUtils { | |
/** | |
* @return | |
* @throws NoSuchAlgorithmException | |
*/ | |
public static String md5encode(String message) throws NoSuchAlgorithmException{ | |
MessageDigest m=MessageDigest.getInstance("MD5"); | |
m.update(message.getBytes(),0,message.length()); | |
System.out.println("MD5: "+new BigInteger(1,m.digest()).toString(16)); | |
return new BigInteger(1,m.digest()).toString(16); | |
} | |
public static String sha256encode(String message) throws NoSuchAlgorithmException{ | |
MessageDigest m=MessageDigest.getInstance("SHA-256"); | |
m.update(message.getBytes(),0,message.length()); | |
System.out.println("SHA-256: "+new BigInteger(1,m.digest()).toString(16)); | |
return new BigInteger(1,m.digest()).toString(16); | |
} | |
public static String basicAuth(String username, String password) { | |
System.out.println("Basic " + new BASE64Encoder().encodeBuffer((username+ ":"+password).getBytes()).replace("\n", "").replace("\r", "")); | |
return "Basic " + new BASE64Encoder().encodeBuffer((username+ ":"+password).getBytes()).replace("\n", "").replace("\r", ""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment