473,785 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Encryp t("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.To String 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 3593
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. FromBase64Strin g(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.Encryp t("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.To String 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. FromBase64Strin g(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.Encryp t("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.To String 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
3127
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: /* Allocate 1st dimension */ if((Screen = (Atom ***) malloc(sizeof(Atom **) * Width)) == NULL) perrexit("malloc");
5
1604
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 copying. Something like this.
5
9842
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 the memory across. Using Marshal.PtrStructure doesn't work - it says my byte() array is not blittable! (byte is a blittable type however). Cannot use Marshal.Copy, because that works the other way around (for mashalling to COM, not from it). ...
6
2785
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) using redim arrays to add to a normal byte array (2) using an ArrayList and finally (3) using a memorystream. These three classes are listed below the test sub called "TestBuildByteArray". It was interesting that using the memorystream was...
1
3012
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 89600 element byte array eah element specifying the pixel color. I need to convert this into a Bitmap tho. Does anyone have any ideas on how to do this or even if there is something already around that can do this for me?
5
2867
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 example, think of a TV screen where only the top third shows anything, and what is does show is repeated 3 times. The code should skip through an array of bytes, taking them in groups of three, and then writing the results of a calculation on the...
24
2294
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
4524
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
7207
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 Marshal.PtrToStructure to copy the all the data into the "other" array? unsafe public struct DeadReckoning {
9
5171
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 level parsing what ever may be the type of data.The data would be coming from an external environment.When I parse int,char at byte level,I get right values,where as floating point just prints 0.000000 to the screen.Given below is a sample program...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.