Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 8th, 2006, 10:49 AM   #1
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
ascii vs base64 encodings

I need some help understanding what base64 is used for and how it is determined. I have been researching password encryption techniques and say for the salt example below, why is base64 used to generate the salt instead of ascii?

public static System.String CreateSalt( System.Int32 size )
        {
            // Instantiate a cryptographic random number generator.
            System.Security.Cryptography.RNGCryptoServiceProvider rng =
                new System.Security.Cryptography.RNGCryptoServiceProvider();

            // Create an array to hold the randomly generated bytes.
            System.Byte[] randomBytes = new System.Byte[ size ];

            // Fill the array with randomly generated bytes.
            rng.GetBytes( randomBytes );

            // Return a Base64 string representation of the random number.
            return System.Convert.ToBase64String( randomBytes );
        }
hoffmandirt is offline   Reply With Quote
Old May 8th, 2006, 2:12 PM   #2
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,194
Rep Power: 5 lectricpharaoh will become famous soon enough
I think the idea is that if it is returned as ASCII, it can be easily manipulated as text. While this isn't an issue for the actual algorithms, it is an issue if you'd like to save it as text, or transmit it as part of a message. You might well want to transmit it in order to mix symmetric and asymmetric encryption, so you send the key (used for symmetric encryption) in an email encrypted with asymmetric encryption (like PGP), and when the other parties have received this key in a secure manner, you can then use symmetric encryption for the rest of the rest of the session. Lots of systems mix symmetric and asymmetric in this manner, using the latter only to transmit 'session keys' for the former, and if you cannot do binary transmissions easily, plain ASCII is a good alternative.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is online now   Reply With Quote
Old May 8th, 2006, 6:09 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Base64-encoded data can be sent through a number of mediums not available to Base256-encoded data (what you've referred to as ASCII) - URL strings, for example.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 8th, 2006, 6:30 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
When did they start calling ASCII Base256? I may puke.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 8th, 2006, 10:51 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,086
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
I think Ooble's throwing out terms. http://en.wikipedia.org/wiki/Ascii

Nothing about base 256 there...

http://en.wikipedia.org/wiki/Base256

Article doesn't exist. Try searching for the term "base 256", doesn't exist anywhere either.
Sane is offline   Reply With Quote
Old May 8th, 2006, 11:21 PM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Base: In mathematics, a base is the number of single digits denoting different values in a positional numeral system, including zero. For example, the decimal system, the most common system in use today, uses base ten, hence the maximum number a single digit will ever reach is 9, after this it is necessary to add another digit to achieve a higher number.

Base 256 does indeed exists... and it would be represented by a system of 256 unique symbols... wether math can accurately allow them to be ASCII's or if there is limitations to this kind of thing, I don't know.
__________________

tempest is offline   Reply With Quote
Old May 8th, 2006, 11:37 PM   #7
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,086
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Well, I know it obviously does exist. I earlier concieved base 16777216... (no joke). It's whether or not base 256 has any practical uses, let alone represent the ASCII character set.
Sane is offline   Reply With Quote
Old May 9th, 2006, 12:17 AM   #8
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Base 256 is referring to the 256 values of a byte.

ASCII represents a single character in seven bits. For obvious reasons, each character takes up one byte with the most significant bit unused.

If you slap a random series of bits together and call it an ascii string then it will look pretty funky. A fraction of the available 256 values are printable characters.

This is where base 64 comes in. When you have arbitrary binary data, picture crypto salt etc, you might not want null bytes and unprintable characters and such in your output (Such as the many common cases in which such sequences are not allowable). It is a way of encoding this data such that you can send it in text-only mediums due to the fact that it results in a narrow selection of printable characters. Take email for example, specifically the SMTP protocol...
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old May 9th, 2006, 6:50 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
My point is that "Base 256" is a misnomer. Of course there's a base 256, but ASCII isn't it. Let 'em call it "Capacity 256" (or more accurately, Capacity 128).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 9th, 2006, 1:24 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Well, ASCII is one interpretation of what you might call "base 128". I apologise - didn't want to throw anyone there. I was using "base 256" as most character sets (UTF-16 notwithstanding) consist of eight bits.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:24 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC