Hello,
I am currently working on converting a method we have written using Classic ASP into a C# .Net DLL and I've come across a stumbling block.
What we have is an encrypted string stored in a registry setting that we retrieve and decrypt using a HexToBinary function. I have managed to duplicate the Hex string that is created by the ASP code via C# using a modified HexToBinary function and receive a variant byte array back when I call FromString method of the XceedEncryption class:
<code>
public static object HexToBinary(string strHexValue, XceedEncryption xDecrypter)
{
int i = 0;
long lngVal;
string tmpHexValue = "";
string strBinaryValue = "";
object varBinaryValue = new object();
StringBuilder sb = new StringBuilder();
try
{
while (i < strHexValue.Length)
{
tmpHexValue = strHexValue.Substring(i, 2);
lngVal =
long.Parse(tmpHexValue, NumberStyles.AllowHexSpecifier);
sb.Append(
Convert.ToChar(lngVal).ToString());
i += 2;
}
strBinaryValue = sb.ToString();
varBinaryValue = xDecrypter.FromString(strBinaryValue);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return varBinaryValue;
}
</code>
From the ASP code I saw that the result of the call to the Decrypt method is simply cast to a string and there you get your resulting decrypted string. This won't work in C#, at least I can't get it to so I just have the byte array:
<code>
varDataToDecrypt = HexToBinary(strEncrypt, xDecrypter);
varDataDecypted = (
byte[])xDecrypter.Decrypt(ref varDataToDecrypt, true);
</code>
I am getting a variant byte array back from the Decrypt method in C# so it looks like it good until I need to return the actual decrypted string. I'm just not sure how to get the resulting string from the byte array. I'm not all that great with C# yet (if you can't tell) so I apologize for any sloppy code.
Thanks in advance,
Tony