hussainAbid
asked on
Decryption problem using C#
Hej I am trying to decrypt a password using a key and the following line is return empty byte Array...
ICryptoTransform t = des.CreateDecryptor();
byte[] resultArray = t.TransformFinalBlock(buf, 0, buf.Length);
Please help me it is really urgent.......
Thanks in advanced
ICryptoTransform t = des.CreateDecryptor();
byte[] resultArray = t.TransformFinalBlock(buf,
Please help me it is really urgent.......
Thanks in advanced
private static string Decrypt(string source, string key, Encoding encoding) {
byte[] buf;
TripleDESCryptoServiceProvider des = GetDESService(key, encoding);
buf = Convert.FromBase64String(source);
ICryptoTransform t = des.CreateDecryptor(); //new line
byte[] resultArray = t.TransformFinalBlock(buf, 0, buf.Length);//here it returns empty byte arrat
String decryptedStr = encoding.GetString(resultArray); //new line
return decryptedStr ;
}
private static TripleDESCryptoServiceProvider GetDESService(string key, Encoding encoding)
{
MD5CryptoServiceProvider hashmd5;
TripleDESCryptoServiceProvider des;
byte[] pwdhash;
hashmd5 = new MD5CryptoServiceProvider();
pwdhash = hashmd5.ComputeHash(encoding.GetBytes(key));
des = new TripleDESCryptoServiceProvider();
des.Key = pwdhash;
des.Mode = CipherMode.ECB;
des.Padding = PaddingMode.PKCS7;
return des;
}
Does buf have anything in it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There was nothing in buf right .. no password :)
buf = Convert.FromBase64String(s ource);
might want to check for null or 0 length
buf = Convert.FromBase64String(s
might want to check for null or 0 length
ASKER
There was an encoded empty string and thats exactly what our business partner were sending to us due to wrong parameters set by us towards the call ...
So It was me ..... Sorry
So It was me ..... Sorry
Any chance of getting the points :)
Maybe you can try to use a memorystream (see attached code). It's what I'm using in my application.
Julien
Open in new window