User (Old forums)MemberDecember 16, 2008 at 2:57 pmPost count: 23064
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:
public static object HexToBinary(string strHexValue, XceedEncryption xDecrypter)
int i = 0;
string tmpHexValue = “”;
string strBinaryValue = “”;
object varBinaryValue = new object();
StringBuilder sb = new StringBuilder();
while (i < strHexValue.Length)
tmpHexValue = strHexValue.Substring(i, 2);
i += 2;
strBinaryValue = sb.ToString();
varBinaryValue = xDecrypter.FromString(strBinaryValue);
catch (Exception ex)
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:
varDataToDecrypt = HexToBinary(strEncrypt, xDecrypter);
varDataDecypted = (
byte)xDecrypter.Decrypt(ref varDataToDecrypt, true);
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,
Imported from legacy forums. Posted by Tony (had 3995 views)Xceed SupportMemberDecember 17, 2008 at 11:44 amPost count: 5658
To get the resulting string, data, from your byte array, varDataDecypted, you will need to use a Text Encoding as follow:
string data = System.Text.Encoding.Unicode.GetString( ( byte )varDataDecypted );
Imported from legacy forums. Posted by Mohamed [Xceed] (had 514 views)User (Old forums)MemberDecember 18, 2008 at 2:22 pmPost count: 23064
Thanks for the reply Mohamed.
It returned part of the string I was looking for but most of it was just garbled, like special character boxes. I must have not set things up right.
Imported from legacy forums. Posted by Tony (had 5744 views)
You must be logged in to reply to this topic.