views:

111

answers:

3

Hi,

I want to convert the Rijndaemanaged() encrpted value to a string.

Will ToBase64String() suffice? It says its only for 8-bit arrays, but AES is 128 bit right?

Update

For the encrption, I am using the code from http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx

A: 

Byte is byte = 8bits. ToBase64String will work. As Jon points out, it has limitations in using it in urls or filenames.

You can use this to convert it to a hex string.

Sunny
what do you mean, overhead in the conversion?
A hex string will be longer than a base64 string! (With hex, string length = 2 * binary length; with base 64, string length = (4/3) * binary length)
Jon Skeet
Ops, actually I had a reason to choose hex, and when I reviewed my notes, it was because of "link" and filename issues you mention in your answer. editing ... and +1
Sunny
+2  A: 

Base64 is a generally good way to go. It's reasonably efficient, and you usually don't need to worry about encoding issues as the result will be ASCII. However, you should probably be careful if you're going to use the result in a URL - "normal" Base64 isn't url-safe. (There are alternative encodings which use different symbols though.)

Jon Skeet
Jon, how about to go from the string back to a byte array? Should I use Encoding.ASCII.GetBytes(); ?
No - use Convert.FromBase64String. You've always got to apply encodings/decodings in pairs like that.
Jon Skeet
Jon, makes sense, thanks a bundle.
when you say 'reasonably inefficient' you are referring to the speed of the conversion? If yes, is there an alternative?
I meant reasonably efficient, actually. Will edit! (I meant it in terms of length - there's not very much bloat.)
Jon Skeet
A: 

We have been succesfully using Convert.ToBase64String on the encrypted bytes from managed Rijndael for number of years.

Brad Patton