15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Symmetric/Asymmetric Encryption Algorithms 453<br />

One type of algorithm commonly associated<br />

with encryption is a hash function. A hash function<br />

takes data as input and based on the size<br />

and content of that data, the hash function calculates<br />

a unique mathematical value. This<br />

value isn’t used as part of the encryption but as<br />

a way to authenticate that certain data hasn’t<br />

been altered.<br />

Hash functions are often used when downloading<br />

files. A Web site might offer a file <strong>for</strong><br />

download and display its hash value. Now if<br />

Hash functions<br />

you download that file and run that file through<br />

the hash function, you should get the same<br />

hash value. If you get a different value, the file<br />

you downloaded is corrupt and missing some<br />

in<strong>for</strong>mation. In encryption, hash functions can<br />

verify that an encrypted message hasn’t been<br />

altered. If a file has been altered, it could mean<br />

the file simply got corrupted, or that someone<br />

tried to insert or remove data from the encrypted<br />

message, which means you shouldn’t trust the<br />

validity of that message.<br />

The biggest problem with symmetric encryption is that both parties need the<br />

same password to encrypt and decrypt data, so if you can’t securely transfer<br />

the password to someone else, that person can never read the message.<br />

A second problem with symmetric encryption is that the weakest link is the<br />

password itself. The encryption algorithm could be the strongest in the<br />

world, but if someone steals the password, that’s like giving someone the<br />

key to unlock the ten-foot-thick steel doors guarding all the gold in the vault<br />

of Fort Knox.<br />

Some popular symmetric encryption algorithms include the Data Encryption<br />

Standard (DES) and the Advanced Encryption Standard (AES). DES was the<br />

original government encryption standard approved in 1976. After computers<br />

became fast enough, they could crack DES encryption; so after a five-year<br />

contest between cryptographers, the government selected a new encryption<br />

standard — AES.<br />

Symmetric encryption is often called private-key encryption because both the<br />

sender and the receiver need an identical copy of the key to encrypt and<br />

decrypt a message. Another type of encryption algorithm is the asymmetric,<br />

or public-key encryption. Unlike symmetric encryption, asymmetric encryption<br />

requires two keys <strong>for</strong> both the sender and the receiver.<br />

These two keys are the public key and the private key. You can make a million<br />

copies of your public key and give them out, but you want only one copy of<br />

your private key. If someone wants to send you a message, he needs to encrypt<br />

a message with your public key. After someone encrypts a message with<br />

your public key, the only way to decrypt that message is to use your private<br />

key, as shown in Figure 5-5.<br />

Book IV<br />

Chapter 5<br />

Encryption<br />

Algorithms

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!