PC Review


Reply
Thread Tools Rate Thread

Byte Array to Screen-Printable String and back again

 
 
=?Utf-8?B?QnJ5YW4=?=
Guest
Posts: n/a
 
      15th Jul 2004
Apologies if this is a noob question, but I've been struggling with this for quite a while...

I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string that is displayed in a text box. Once displayed, the text will be copied, transmitted and then pasted (all manually by humans) into a second utility where the string must then be reverse-engineered into the *original* byte array. The byte array will then be decrypted by the second app.

I've got the encryption/decryption piece sorted, I'm just struggling with the screen-printable text bit...

I've tried many of the suggestions posted on the web for converting the byte array into a screen-printable string. All have worked, and I've settled on the following:

Dim Bytes() As Byte = myCrypto.Encrypt("AuthCode") ' .Encrypt returns a byte array
Dim myBitConverter As BitConverter
txtBox.Text = myBitConverter.ToString(Bytes)
' Displayed as XX-XX-XX-XX... in the txtBox.

The problem is that for all of the examples I've found on the internet, none have helped me reverse engineer the screen-printable string into the original byte array. Although I like the BitConverter.ToString format (XX-XX-XX-XX) used in the code above, I don't really care how the string looks - as long as it is screen-printable and can be displayed, copied, emailed and pasted without issue. Can you enlighten me as to how I can easily convert a byte array to a screen-friendly string and then back again?

Many thanks in advance.
Bryan
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWJ1YmFrYXI=?=
Guest
Posts: n/a
 
      15th Jul 2004
Will converting it to base 64 be any good to you, like:
mybuffer is your byte array and you write:
Dim data64 As String= System.Convert.ToBase64String(mybuffer, 0, mybuffer.Length)
now "data64" contains a string representation of the byte array. You can type it in a textbox and the other guy can take that string and through the following statement get the original byte array back:

Dim b() As Byte = System.Convert.FromBase64String(data64)

Its sort of what the ViewState in ASP.net does.

Hope that helps.

Abubakar.
http://joehacker.blogspot.com
--------------------------------------

"Bryan" wrote:

> Apologies if this is a noob question, but I've been struggling with this for quite a while...
>
> I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string that is displayed in a text box. Once displayed, the text will be copied, transmitted and then pasted (all manually by humans) into a second utility where the string must then be reverse-engineered into the *original* byte array. The byte array will then be decrypted by the second app.
>
> I've got the encryption/decryption piece sorted, I'm just struggling with the screen-printable text bit...
>
> I've tried many of the suggestions posted on the web for converting the byte array into a screen-printable string. All have worked, and I've settled on the following:
>
> Dim Bytes() As Byte = myCrypto.Encrypt("AuthCode") ' .Encrypt returns a byte array
> Dim myBitConverter As BitConverter
> txtBox.Text = myBitConverter.ToString(Bytes)
> ' Displayed as XX-XX-XX-XX... in the txtBox.
>
> The problem is that for all of the examples I've found on the internet, none have helped me reverse engineer the screen-printable string into the original byte array. Although I like the BitConverter.ToString format (XX-XX-XX-XX) used in the code above, I don't really care how the string looks - as long as it is screen-printable and can be displayed, copied, emailed and pasted without issue. Can you enlighten me as to how I can easily convert a byte array to a screen-friendly string and then back again?
>
> Many thanks in advance.
> Bryan

 
Reply With Quote
 
=?Utf-8?B?QnJ5YW4=?=
Guest
Posts: n/a
 
      15th Jul 2004
Initial results are looking VERY promising. Thank you so much for taking the time to help me!!

Bryan


"Abubakar" wrote:

> Will converting it to base 64 be any good to you, like:
> mybuffer is your byte array and you write:
> Dim data64 As String= System.Convert.ToBase64String(mybuffer, 0, mybuffer.Length)
> now "data64" contains a string representation of the byte array. You can type it in a textbox and the other guy can take that string and through the following statement get the original byte array back:
>
> Dim b() As Byte = System.Convert.FromBase64String(data64)
>
> Its sort of what the ViewState in ASP.net does.
>
> Hope that helps.
>
> Abubakar.
> http://joehacker.blogspot.com
> --------------------------------------
>
> "Bryan" wrote:
>
> > Apologies if this is a noob question, but I've been struggling with this for quite a while...
> >
> > I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string that is displayed in a text box. Once displayed, the text will be copied, transmitted and then pasted (all manually by humans) into a second utility where the string must then be reverse-engineered into the *original* byte array. The byte array will then be decrypted by the second app.
> >
> > I've got the encryption/decryption piece sorted, I'm just struggling with the screen-printable text bit...
> >
> > I've tried many of the suggestions posted on the web for converting the byte array into a screen-printable string. All have worked, and I've settled on the following:
> >
> > Dim Bytes() As Byte = myCrypto.Encrypt("AuthCode") ' .Encrypt returns a byte array
> > Dim myBitConverter As BitConverter
> > txtBox.Text = myBitConverter.ToString(Bytes)
> > ' Displayed as XX-XX-XX-XX... in the txtBox.
> >
> > The problem is that for all of the examples I've found on the internet, none have helped me reverse engineer the screen-printable string into the original byte array. Although I like the BitConverter.ToString format (XX-XX-XX-XX) used in the code above, I don't really care how the string looks - as long as it is screen-printable and can be displayed, copied, emailed and pasted without issue. Can you enlighten me as to how I can easily convert a byte array to a screen-friendly string and then back again?
> >
> > Many thanks in advance.
> > Bryan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net:converting from byte array to string and back again movieknight@gmail.com Microsoft Dot NET 4 8th Apr 2006 09:48 AM
Re: Byte Array to Screen-Friendly String - and back again? Cablewizard Microsoft VB .NET 0 4th Aug 2004 09:28 PM
Re: Byte Array to Printable String to Byte Array Jon Skeet [C# MVP] Microsoft Dot NET 0 4th Aug 2004 01:53 PM
Byte array to string and back - newbie question =?Utf-8?B?cG9wc292eUBydXNtZXguY29t?= Microsoft Dot NET Framework 2 5th Feb 2004 07:47 PM
string >> byte array >> string representation >> byte array >> string !! David Bargna Microsoft VB .NET 4 6th Oct 2003 04:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.