![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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 );
} |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
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. |
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
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.
__________________
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
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.
|
|
|
|
|
|
#8 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#10 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|