By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,667 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,667 IT Pros & Developers. It's quick & easy.

Hex Converter Problem

P: n/a
Hey All,

I know this is probably stupid question. This is what I am trying to do:

I am trying to encrypt using Twofish then I take each character and change
it into the Hex value for it. Here is what I have:

Twofish tf = new Twofish();

tf.Mode = CipherMode.ECB;

byte[] plainText = Twofish.StrToByteArray(this.TextBoxEnter.Text);

System.IO.MemoryStream ms = new System.IO.MemoryStream();

ICryptoTransform encrypt = tf.CreateEncryptor(plainText);

//Create Crypto Stream that transforms file stream using twofish encryption

CryptoStream cryptostream = new
CryptoStream(ms,encrypt,CryptoStreamMode.Write);

//write out Twofish encrypted stream

cryptostream.Write(plainText,0,plainText.Length);

cryptostream.Close();

byte[] bytOut = ms.ToArray();

string output = Twofish.ByteArrayToStr(bytOut);

//Here is where I need to convert it to hex

//Lets say the output string is #4ff&* I need to change

//Hex of each character
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
It isn't clear what you are trying to convert. It also isn't clear how
any of your included code is relevant.

State the question like this: I want a fuctino that takes an input of
data type X, that looks like Y. I would like the output to be of data
type A, and look like B. And tell us what X, Y, A, and B are.

Generally, if you are trying to convert a numeric value to a hex string
(which I'm not sure if you do), you can pass "X" to a ToString() method
that accepts a format string.

For example:

Byte b = 255;
Console.WriteLine(b.ToString("X"));

output:
FF

Sean McKaharay wrote:
Hey All,

I know this is probably stupid question. This is what I am trying to do:

I am trying to encrypt using Twofish then I take each character and change
it into the Hex value for it. Here is what I have:

Twofish tf = new Twofish();

tf.Mode = CipherMode.ECB;

byte[] plainText = Twofish.StrToByteArray(this.TextBoxEnter.Text);

System.IO.MemoryStream ms = new System.IO.MemoryStream();

ICryptoTransform encrypt = tf.CreateEncryptor(plainText);

//Create Crypto Stream that transforms file stream using twofish encryption

CryptoStream cryptostream = new
CryptoStream(ms,encrypt,CryptoStreamMode.Write);

//write out Twofish encrypted stream

cryptostream.Write(plainText,0,plainText.Length);

cryptostream.Close();

byte[] bytOut = ms.ToArray();

string output = Twofish.ByteArrayToStr(bytOut);

//Here is where I need to convert it to hex

//Lets say the output string is #4ff&* I need to change

//Hex of each character

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.