Hi,
I'm trying to decrypt within a java program a string encrypted with
CryptoAPI in .Net. I really can't get a good result from this. Could
anyone tell me how can a decrypt this with java?
The funtion used to encrypt is this one (in C#):
public static string DecryptData(string password, string
encryptedBase64Value)
{
string __Data;
byte[] __EncryptedBytes;
byte[] __TextBytes;
System.Security.Cryptography.TripleDES __CryptoProvider;
System.Security.Cryptography.PasswordDeriveBytes
__PasswordDeriveBytes;
System.Security.Cryptography.CryptoStream __CryptoStream;
System.IO.MemoryStream __MemoryStream;
__CryptoProvider =
System.Security.Cryptography.TripleDES.Create();
__CryptoProvider.IV = new byte[8];
__PasswordDeriveBytes = new
System.Security.Cryptography.PasswordDeriveBytes(password, new
byte[0]);
__CryptoProvider.Key =
__PasswordDeriveBytes.CryptDeriveKey("RC2", "MD5", 128, new
byte[8]);
__EncryptedBytes =
System.Convert.FromBase64String(encryptedBase64Value);
__MemoryStream = new
System.IO.MemoryStream(encryptedBase64Value.Length);
__CryptoStream = new
System.Security.Cryptography.CryptoStream(__MemoryStream,
__CryptoProvider.CreateDecryptor(),
System.Security.Cryptography.CryptoStreamMode.Write);
__CryptoStream.Write(__EncryptedBytes, 0,
__EncryptedBytes.Length);
__CryptoStream.FlushFinalBlock();
__TextBytes = new byte[__MemoryStream.Length];
__MemoryStream.Position = 0;
__MemoryStream.Read(__TextBytes, 0, (int)__MemoryStream.Length);
__CryptoStream.Close();
__Data = System.Text.Encoding.UTF8.GetString(__TextBytes);
return __Data;
}
Thanks!!!


|