473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3554
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Fabian Wauthier | last post by:
Hi list, I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of pointers to a struct Atom (i.e. the head of a linked list). I am not sure if this is the right way to do it: ...
5
by: Olaf Baeyens | last post by:
I have another problem, maybe it is simple to fix. I have this: byte Test=new byte; But I now want to have a second pointer Test2 to point to a location inside this Test. But with no...
5
by: Robin Tucker | last post by:
I need to marshal an IntPtr (which I've got from GlobalLock of an HGLOBAL) into a byte array. I know the size of the array required and I've got a pointer to the blob, but I can't see how to copy...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
1
by: Sauny | last post by:
Hi all, Ok, I am not the best C programmer in the world but am looking to convert a byte array which contains pixel information to a bitmap. basically i have a screen say 320x280 leading to a...
5
by: paul | last post by:
Hi all, Could some kind soul peruse the following code and see if there is anything wrong with it? Its producing output, but its only occupying the first third of the output array; to give an...
24
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
11
by: Garth Wells | last post by:
I've got code that allows me to render the contents of a byte array to the screen, but I need to write the contents to disk. Suggestions? Thanks
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
9
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.