Rijndael - Best Way To Load Keys

  • Thread starter Thread starter Amy L.
  • Start date Start date
A

Amy L.

I have a client / server application. I just want to encrypt small amounts
of data 1<x<1024 characters or so. I need to load the same Key and IV in
both applications. However, both the key and IV are byte arrays.

What is the best way to get the keys loaded in both applications?

For example in RSA you can export the keys to XML. Can you do this in
Rijndael? I tried using System.Text.Encoding.UTF8 or ASCII, but this does
not appear to convert the keys correctly to strings I sense this is because
some of the bytes are high characters and not encoded properly.

I am not too concerned with having static keys loaded in the apps. My main
concern is just making the data passing between both systems non-human
readable if sniffed.

Thanks
Amy.
 
I tried using System.Text.Encoding.UTF8 or ASCII, but this does
not appear to convert the keys correctly to strings I sense this is because
some of the bytes are high characters and not encoded properly.

The byte arrays can easily be base64 encoded using
Convert.ToBase64String(byte[]). Alternatively, you can store the byte
values in a file using System.IO.BinaryWriter.

-Derek
 
You should look into the Convert.ToBase64, suitable for loading into an XML
File...

basically base64 is a tried and true way to encode byte arrays to text,
albeit at a cost of size expansion of 2:3 (i believe)

Nonetheless, its an easy way and for the most part, de-facto standard way to
store byte arrays in Xml

HTH
 
Depending on the data transfer protocol, you can do one of a number of
things. If you are exchanging data over HTTP, then base64 is probably the
best way to move byte arrays around (as text). However, if you have a basic
TCP connection, you can write the byte array directly to the network stream
and read it on the other side.

However, the biggest concern is that you are tossing the key into the
network/internet (wherever) and whoever grabs hold of it will be able to
unlock all your cipher data traffic. I recommend running your key and IV
through the RSAxxxxKeyExchangeFormatter/Deformatter class first - or use a
key exchange algorithm that derrives the same key at both ends based on some
seed data instead of transferring the key directly over the wire. You can
find a ton of data on key exchange algorithms by doing a search on google.

-Rob Teixeira [MVP]

Eric Newton said:
You should look into the Convert.ToBase64, suitable for loading into an XML
File...

basically base64 is a tried and true way to encode byte arrays to text,
albeit at a cost of size expansion of 2:3 (i believe)

Nonetheless, its an easy way and for the most part, de-facto standard way to
store byte arrays in Xml

HTH


--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(e-mail address removed)-software.com [remove the first "CC."]

Amy L. said:
I have a client / server application. I just want to encrypt small amounts
of data 1<x<1024 characters or so. I need to load the same Key and IV in
both applications. However, both the key and IV are byte arrays.

What is the best way to get the keys loaded in both applications?

For example in RSA you can export the keys to XML. Can you do this in
Rijndael? I tried using System.Text.Encoding.UTF8 or ASCII, but this does
not appear to convert the keys correctly to strings I sense this is because
some of the bytes are high characters and not encoded properly.

I am not too concerned with having static keys loaded in the apps. My main
concern is just making the data passing between both systems non-human
readable if sniffed.

Thanks
Amy.
 
Back
Top