Byte array to string and back - newbie question

popsovy_at_rusmex.com
Date: 02/05/04


Date: Wed, 4 Feb 2004 21:06:06 -0800

Hi,

I am trying to implement DES algorithm as described in the Microsoft article at
http://msdn.microsoft.com/library/en-us/dnnetsec/html/SecNetHT10.asp.

The problem is that I need to save the data in the database as String, and for that I have to convet from Byte array to string and back.

When I cast a byte array into a string and then back to a byte array, I don't get the same array. For example:

Dim SecretText As Byte()
Dim SecretText1 As Byte()
Dim Text as string
.....
SecretText = enc.Encrypt(Data, Key, Vector) 'returns Byte Array
Text = Encoding.ASCII.GetString(SecretText) 'convert to string in order to save into the DB
....
....
....
SecretText1 = Encoding.ASCII.GetBytes(Text) 'prepare for decryption routine

At the end, SecretText1 does NOT equal to SecretText, and I want it to be. How should I do the conversion correctly?

Thanks!!!

Zhenya
http://www.rusmex.com



Relevant Pages

  • Re: What could be the problem with this INSERT with ADO parameters?
    ... The only way I have found sofar is to enclose the string in single ... written to the database. ... But that gives the same problem, it actually crashes Excel. ... how do I handle a string with comma's in the parameter array? ...
    (microsoft.public.data.ado)
  • Re: What could be the problem with this INSERT with ADO parameters?
    ... The only way I have found sofar is to enclose the string in single ... written to the database. ... But that gives the same problem, it actually crashes Excel. ... how do I handle a string with comma's in the parameter array? ...
    (microsoft.public.data.ado)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)