Created
August 6, 2014 17:17
-
-
Save dilnei/00b43893f4840e91efaa to your computer and use it in GitHub Desktop.
Criptografa com SHA Base46
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
| package br.com.risingforce.geradores; | |
| import java.security.MessageDigest; | |
| import java.security.NoSuchAlgorithmException; | |
| import org.apache.commons.codec.binary.Base64; | |
| /** | |
| * <b>Classe responsável por criptografar com SHA Base46.</b> | |
| * | |
| * @author Dilnei Cunha. | |
| */ | |
| public class SHA256Base64 { | |
| /** | |
| * <b>Método que retorna uma String em SHA-256 Base64</b> | |
| * | |
| * @param str | |
| * @return String | |
| * @throws NoSuchAlgorithmException | |
| */ | |
| public static String criptoSha256Base64(String str) throws NoSuchAlgorithmException { | |
| final MessageDigest messageDigest = java.security.MessageDigest.getInstance("SHA-256"); | |
| final byte bin[] = messageDigest.digest(str.getBytes()); | |
| return Base64.encodeBase64String(bin); | |
| } | |
| /** | |
| * <b>Método que retorna uma String em SHA-512 Base64</b> | |
| * | |
| * @param str | |
| * @return String | |
| * @throws NoSuchAlgorithmException | |
| */ | |
| public static String criptoSha512Base64(String str) throws NoSuchAlgorithmException { | |
| final MessageDigest messageDigest = java.security.MessageDigest.getInstance("SHA-512"); | |
| final byte bin[] = messageDigest.digest(str.getBytes()); | |
| return Base64.encodeBase64String(bin); | |
| } | |
| /** | |
| * <b>Método que retorna uma String em SHA-1 Base64</b> | |
| * | |
| * @param str | |
| * @return String | |
| * @throws NoSuchAlgorithmException | |
| */ | |
| public static String criptoSha1Base64(String str) throws NoSuchAlgorithmException { | |
| final MessageDigest messageDigest = java.security.MessageDigest.getInstance("SHA-1"); | |
| final byte bin[] = messageDigest.digest(str.getBytes()); | |
| return Base64.encodeBase64String(bin); | |
| } | |
| /** | |
| * <b>Método que retorna uma String em SHA-384 Base64</b> | |
| * | |
| * @param str | |
| * @return String | |
| * @throws NoSuchAlgorithmException | |
| */ | |
| public static String criptoSha384Base64(String str) throws NoSuchAlgorithmException { | |
| final MessageDigest messageDigest = java.security.MessageDigest.getInstance("SHA-384"); | |
| final byte bin[] = messageDigest.digest(str.getBytes()); | |
| return Base64.encodeBase64String(bin); | |
| } | |
| /** | |
| * <b>Método que retorna uma String em MD2 Base64</b> | |
| * | |
| * @param str | |
| * @return String | |
| * @throws NoSuchAlgorithmException | |
| */ | |
| public static String criptoMD2Base64(String str) throws NoSuchAlgorithmException { | |
| final MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD2"); | |
| final byte bin[] = messageDigest.digest(str.getBytes()); | |
| return Base64.encodeBase64String(bin); | |
| } | |
| /** | |
| * <b>Método que retorna uma String em MD5 Base64</b> | |
| * | |
| * @param str | |
| * @return String | |
| * @throws NoSuchAlgorithmException | |
| */ | |
| public static String criptoMD5Base64(String str) throws NoSuchAlgorithmException { | |
| final MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD5"); | |
| final byte bin[] = messageDigest.digest(str.getBytes()); | |
| return Base64.encodeBase64String(bin); | |
| } | |
| public static void main(String ...as) throws NoSuchAlgorithmException{ | |
| System.out.println(criptoMD5Base64("123456")); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment