Obrigado,
teria como vc postar algum exemplo ou parte de um codigo para eu veisualizar melhor o que eu teria que fazer ?
hoje estou fazendo assim :
MessageDigest md5=null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
md5.update("Elvis esta vivo".getBytes());
md5.
String elvis = new String(md5.digest());
md5.update("Beatles esta vivo".getBytes());
String beatles = new String(md5.digest());
System.out.println(elvis + " >> "+ beatles );
System.out.println("\n iguais ? " + MessageDigest.isEqual(elvis.getBytes(),elvis.getBytes() ));
mas o problema é que nao consigo decriptografar com md5,
tentei utilizar um exemplo que peguei na web, mas esta dando um erro que nao consegui resolver, Ainda, segue codigo abaixo
private static PBEParameterSpec ps = null;
private static final String algorithm = "PBEWithMD5AndDES";
private static BASE64Encoder enc = new BASE64Encoder();
private static BASE64Decoder dec = new BASE64Decoder();
static {
ps = new PBEParameterSpec (new byte[]{3,1,4,1,5,9,2,6}, 20);
}
public static String criptografa(String texto, String senhaCriptografia)throws BadPaddingException,NoSuchPaddingException,IllegalBlockSizeException,InvalidKeyException,NoSuchAlgorithmException,InvalidAlgorithmParameterException, InvalidKeySpecException {
PBEKeySpec ks = new PBEKeySpec (senhaCriptografia.toCharArray()); // esta é a chave que você quer manter secreta.
SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm);
SecretKey skey = skf.generateSecret(ks);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, skey);
return enc.encode (cipher.doFinal(texto.getBytes()));
}
public static String decriptografa(String texto, String senhaCriptografia) throws BadPaddingException,NoSuchPaddingException,IllegalBlockSizeException,InvalidKeyException,NoSuchAlgorithmException,InvalidAlgorithmParameterException, InvalidKeySpecException {
PBEKeySpec ks = new PBEKeySpec (senhaCriptografia.toCharArray()); // esta é a chave que você quer manter secreta.
SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm);
SecretKey skey = skf.generateSecret(ks);
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, skey);
String ret = null;
try {
ret = new String(cipher.doFinal(dec.decodeBuffer (texto)));
} catch (Exception ex) {
}
return ret;
}
mas nao sei qual o nivel de seguranca desta criptografia e o codigo de decriptografia nao funciona.