Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Security > CryptoAPI compa...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 1715 of 1781
Post > Topic >>

CryptoAPI compatibility issue

by Fer <delarasf@[EMAIL PROTECTED] > Jul 29, 2007 at 07:47 PM

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!!!
 




 1 Posts in Topic:
CryptoAPI compatibility issue
Fer <delarasf@[EMAIL P  2007-07-29 19:47:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 5 19:35:22 CDT 2008.