M
manmit.walia
Hello Everyone,
Long time ago, I posted a small problem I had about converting a VB6
program to C#. Well with the help with everyone I got it converted.
But I overlooked something and don't understand why it is doing this.
Below is my code, I would be greatfull if someone can guide me through
the right path or even help me solve this issue.
Problem: The old tool which was written in VB6 works perfect. But I
needed to convert this to C# using since there are new tools we are
creating that would like to leverage this style of security. The
problem is that the encryption method is not working as it should. The
decryption method works perfect. Just having problems with the
encryption part.
Test Values:
Current Encrypted Value - 0835262B27
Value returned using Decrypt method - anna
Current Decrypted Value - anna
Value returned using Encrypted method - 35262B27
*** As you can see the encryption method is returning something
different then the original encrypted value. *** PLEASE HELP !!! ***
CODE:
static byte[] ParseHex(string text)
{
byte[] ret = new byte[text.Length / 2];
for (int i = 0; i < ret.Length; i++)
{
ret = Convert.ToByte(text.Substring(i * 2, 2), 16);
}
return ret;
}
public static string Decrypt("THEFELDGROUP", string encrypted)
{
byte[] binary = ParseHex(encrypted);
char[] chars = new char[binary.Length];
for (int i = 0; i < chars.Length; i++)
{
chars = (char)(binary ^ password[i % password.Length]);
}
return new string(chars);
}
public static string Encrypt("THEFELDGROUP", string
strG)
{
char[] cHexDigits = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
// the encoded integer value of the current character in the string
byte byteEncoded;
System.Text.StringBuilder sbReturned = new
System.Text.StringBuilder();
for (int i = 0; i < strG.Length; ++i)
{
// encode the current character
byteEncoded = (byte)(((int)strG) ^ ((int)strPass[i %
strPass.Length]));
// output the Hex character value of the above encoded value
sbReturned.Append(cHexDigits[byteEncoded >>
4]).Append(cHexDigits[byteEncoded & 0xF]);
}
return sbReturned.ToString();
}
Long time ago, I posted a small problem I had about converting a VB6
program to C#. Well with the help with everyone I got it converted.
But I overlooked something and don't understand why it is doing this.
Below is my code, I would be greatfull if someone can guide me through
the right path or even help me solve this issue.
Problem: The old tool which was written in VB6 works perfect. But I
needed to convert this to C# using since there are new tools we are
creating that would like to leverage this style of security. The
problem is that the encryption method is not working as it should. The
decryption method works perfect. Just having problems with the
encryption part.
Test Values:
Current Encrypted Value - 0835262B27
Value returned using Decrypt method - anna
Current Decrypted Value - anna
Value returned using Encrypted method - 35262B27
*** As you can see the encryption method is returning something
different then the original encrypted value. *** PLEASE HELP !!! ***
CODE:
static byte[] ParseHex(string text)
{
byte[] ret = new byte[text.Length / 2];
for (int i = 0; i < ret.Length; i++)
{
ret = Convert.ToByte(text.Substring(i * 2, 2), 16);
}
return ret;
}
public static string Decrypt("THEFELDGROUP", string encrypted)
{
byte[] binary = ParseHex(encrypted);
char[] chars = new char[binary.Length];
for (int i = 0; i < chars.Length; i++)
{
chars = (char)(binary ^ password[i % password.Length]);
}
return new string(chars);
}
public static string Encrypt("THEFELDGROUP", string
strG)
{
char[] cHexDigits = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
// the encoded integer value of the current character in the string
byte byteEncoded;
System.Text.StringBuilder sbReturned = new
System.Text.StringBuilder();
for (int i = 0; i < strG.Length; ++i)
{
// encode the current character
byteEncoded = (byte)(((int)strG) ^ ((int)strPass[i %
strPass.Length]));
// output the Hex character value of the above encoded value
sbReturned.Append(cHexDigits[byteEncoded >>
4]).Append(cHexDigits[byteEncoded & 0xF]);
}
return sbReturned.ToString();
}