+ 5

# How does data encryption work?

Can somebody explain me how data encryption in his basics works?

12 Answers

+ 15

Encryption is all about converting data into another form so that only certain parties can read the data. There are typically two kinds of encryption that are commonly used in data science: symmetric key encryption and asymmetric key encryption.
Symmetric key uses a shared key between all the parties that can be used to encrypt and decrypt the data. An incredibly naive way of doing this is called the Caesar Shift. If I was going to use this to send you a message I would tell you how many letters to shift the message to read and write to me.
Hello shifted by 1 becomes Ifmmp
The big weakness to symmetric key encryption is the exchange of the shared key. If it is not properly protected in the handoff everyone now knows what we're sending and the encryption is pointless.
In asymmetric key encryption there are typically two keys used. One is for encrypting messages and the other is for decrypting. I can publicly share the encryption key (called the public key) so that any one can communicate with me. When I receive a message I then use my decryption key (called the private key) to convert it to plain text. I NEVER share the private key with anyone.
This is an incredibly secure way to communicate and is the basis for SSL and HTTPS. It does, however come with much greater complexity and is typically used to exchange a shared key and then the rest of the secure communications happen over symmetric key encryption.
I won't go into an implementation of this type of algorithm because it's too difficult to do justice in this type of app. The brief important part about these algorithms though is that they rely on something that is incredibly hard to solve such as the product of two very large prime numbers. If I gave you a 300 digit number and asked for its prime factors this would be a hard problem to solve. If you want to see a real example check out RSA which is the canonical implementation of this kind of encryption.

+ 6

Encryption works on two different mechanics. Asymmetric and Symmetric encryption. symmetric uses one key to en- and decrypt. Asymetric uses one for each so they are different. Best known example for Asymmetric Encryption is RSA. For Symmetric it's the Caesar chiffre.
In modern programming both of them are used.
Just look for Encryption in Java

+ 6

https://www.coursera.org/learn/cryptography
The course breaks it down for you, including answers to questions like why reversing is hard. It's free.

+ 5

@ein siedler : actually you *should* use standard libraries, they have been tested and are maintained. It is incredibly hard to do a proper, safe, new one from scratch and so usually not recommended.
(except for own experimentation i suppose)

+ 4

James Durand nailed it.
Asymmetric cryptography developed alongside the growth in the Internet.
Simple symmetric cryptography is easier to understand and often much less expensive in terms of CPU time. I'll give an example in a moment but just saying, "better" is subjective and symmetric has its uses still.
Passwords in Linux are stored as hashes of the original value. This is so secure as to make them unrecoverable! Simply applying salt and a hashing algorithm like MD5 or SHA256, multiple times makes then unrecoverable. Apply the same operation to user submitted passwords and you've got SIMPLE symmetric key encryption.
@Suspicious, asker wanted encryption, not cryptography, only cryptography is bidirectional, encryption is not by definition. The next step is cyclic shift registers, easy to imagine, implement, use, and recover (decrypt). But too complicated to describe here. They are a major building block of popular encryption algorithms. And used alone, often a quick fix without introducing another library.

+ 4

So only the receiver knows a. So cracking asymmetrical encryption is difficult because you need all the 5 values and you always have multiple possibilities and don't know which one is right?

+ 4

@ein siedler,
i will explain in easy terms:
by definition, encryption is the act of coverting a plain text (readable) in cipher text ( scrambled).
Now evey type of scrambling is called encryption. think of shifting / substituting each letter with another. hence to can encrpyt text to cipher and then decrpt cipher to original.
what is the problem with the above?
it is easy to guess the encyption algorithm used. to solve this (symmetric) keys are being used where this key is used during shifting (calculation). now an important notice is to have a strong key (long enough) not to be guessed. here comes the 128, 256 and 512 bits keys. but as some members wrote above, the issue of symmetric keys is that the same key is used for both encryption and decryption. hence with the use of asymmetric keys such as RSA for example there are two keys that corresponds with each others (namely private and public key) you can enc with the public and dec with the private. this is often used to exchange symmetric keys.
now in order to know that the key is coming from the authentic sender, the sender can sign the key envelop using the private key and the receiver can verify the envelop using the sender public key.
Hopefully the above gives you a simple introduction to encryption and symmetric vs asymmetric algorithms.
finally note that you do not need to code encryption algorithms yourself, instead use certified ones, such as AES or other ...
it is important to generate and store the keys securely.
for more info about this read more about Host security modules (HSMs).
Cheers,

+ 2

Thank you for all these explanations :) think I got the most important parts now :)

+ 1

So I can use these standard libraries and then it doesn't take that much time?

+ 1

Should be enough for your purposes. Try to look up AES or similar

+ 1

Why can't the key I use to encrypt the file not be used to decrypt it? How does asymmetrical encryption work in its basic layers? I mean how is it possible to have a key which works for encryption but not for decryption?

+ 1

But how can it have two keys? I am not getting it