472,145 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Byte Array to Screen-Printable String and back again

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
Nov 20 '05 #1
2 3472
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

Nov 20 '05 #2
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

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Fabian Wauthier | last post: by
5 posts views Thread by Olaf Baeyens | last post: by
6 posts views Thread by Dennis | last post: by
1 post views Thread by Sauny | last post: by
5 posts views Thread by paul | last post: by
24 posts views Thread by ThunderMusic | last post: by
11 posts views Thread by Garth Wells | last post: by
9 posts views Thread by ssubbarayan | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.