I have the method below in C # and I need to do something equivalent in JAVA, but I can not. Could you help me?
private const string chave = "eMbARaLhaDo";
public static string Descriptografar(string Message)
{
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(chave));
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;
byte[] DataToDecrypt = Convert.FromBase64String(Message);
try
{
ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
}
finally
{
TDESAlgorithm.Clear();
HashProvider.Clear();
}
return UTF8.GetString(Results);
}
I tried the code below, but it did not work:
public static String decodificar(String key, String text) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] encData = new BASE64Decoder().decodeBuffer(text);
Cipher decipher = Cipher.getInstance("AES/ECB/NoPadding");
byte[] tdesKeyData = md.digest(key.getBytes("UTF-8"));
SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "AES");
decipher.init(Cipher.DECRYPT_MODE, myKey);
byte[] plainText = decipher.doFinal(encData);
return new String(plainText);
}