Current location - Loan Platform Complete Network - Big data management - What is the difference between Symmetric Cryptography and Asymmetric Cryptography?
What is the difference between Symmetric Cryptography and Asymmetric Cryptography?
(A) Symmetric Cryptography

Symmetric encryption is the fastest and easiest way to encrypt, encryption (encryption) and decryption (decryption) with the same secret key, this method in cryptography is called symmetric encryption algorithms. Symmetric encryption has many kinds of algorithms, because it is very efficient, so it is widely used in the core of many encryption protocols.

Symmetric encryption usually uses a relatively small key, usually less than 256 bit, because the larger the key, the stronger the encryption, but the slower the encryption and decryption process. If you only use 1 bit for this key, then hackers can try to decrypt it with 0 first, and then with 1 if it doesn't work; but if your key is 1 MB big, hackers may never be able to crack it, but the encryption and decryption process takes a long time. The size of the key is a trade-off between taking care of security and efficiency.

On October 2, 2000, the National Institute of Standards and Technology (NIST - American National Institute of Standards and Technology) selected the Rijndael algorithm as the new Advanced Encryption Standard (AES - Advanced Encryption Standard). NET includes the Rijndael algorithm in a class called RijndaelManaged, an example of which is shown below.

Encryption process:

private string myData = "hello";

private string myPassword = "OpenSesame";

private byte[] cipherText;

private byte[] salt = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0 };

private void mnuSymmetricEncryption_Click(object sender, RoutedEventArgs e)

{

var key = new Rfc2898DeriveBytes(myPassword, salt);

// Encrypt the data.

var algorithm = new RijndaelManaged();

algorithm.Key = key.GetBytes(16);

algorithm.IV = key.GetBytes(16);

var sourceBytes = new System. Text.UnicodeEncoding().GetBytes(myData);

using (var sourceStream = new MemoryStream(sourceBytes))

using (var destinationStream = new MemoryStream())

using (var crypto = new CryptoStream(sourceStream, algorithm.CreateEncryptor(), CryptoStreamMode.Read))

{

moveBytes(crypto, destinationStream);

cipherText = destinationStream.ToArray();

}

MessageBox.Show(String.Format("Data:{0}{1}Encrypted and Encoded:{2}", myData, Environment.NewLine, Convert.ToBase64String( cipherText)));

}

private void moveBytes(Stream source, Stream dest)

{

byte[] bytes = new byte[2048];

var count = source.Read(bytes, 0, bytes.Length);

while (0 ! = count)

{

dest.Write(bytes, 0, count);

count = source.Read(bytes, 0, bytes.Length);

}

}

Decryption process:

private void mnuSymmetricDecryption_Click(object sender, RoutedEventArgs e)

{

if (cipherText == null)

{

MessageBox .Show("Encrypt Data First!");

return;

}

var key = new Rfc2898DeriveBytes(myPassword, salt);

// Try to decrypt, thus showing it can be round-tripped.

var algorithm = new RijndaelManaged();

algorithm.Key = key.GetBytes(16);

algorithm.IV = key .GetBytes(16);

using (var sourceStream = new MemoryStream(cipherText))

using (var destinationStream = new MemoryStream())

using (var crypto = new CryptoStream(sourceStream, algorithm.CreateDecryptor(), CryptoStreamMode.Read))

{

moveBytes(crypto, destinationStream);

var decryptedBytes = destinationStream.ToArray();

var decryptedMessage = new UnicodeEncoding().GetString();

var decryptedMessage = new UnicodeEncoding().

decryptedBytes);

MessageBox.Show(decryptedMessage);

}

}

One of the major drawbacks of symmetric encryption is the management and distribution of the key; in other words, how to get the key into the hands of the person who needs to decrypt your message is a problem. hands is a problem. In the process of sending the key, there is a high risk that the key will be intercepted by hackers. In reality the usual practice is to asymmetrically encrypt a symmetrically encrypted key and then transmit it to the person who needs it.

(2) Asymmetric Cryptography

In 1976, the American scholars Dime and Henman, in order to solve the problem of public transmission of information and key management, proposed a new type of key exchange protocol, which allows the two sides of the communication in an insecure media to exchange information and securely reach a consensus key, which is the "public key system" (PKS). This is "public key system". This method is also called "asymmetric encryption algorithm" as opposed to "symmetric encryption algorithm".

Asymmetric encryption provides a very secure method of encrypting and decrypting data, using a pair of keys, a public key and a private key. The private key can only be held securely by one party and cannot be leaked, while the public key can be sent to anyone who requests it. Asymmetric encryption uses one of these pairs of keys for encryption, while decryption requires the other key. For example, if you request a public key from a bank, and the bank sends it to you, and you use the public key to encrypt a message, then only the holder of the private key - the bank - can decrypt your message. Unlike symmetric encryption, the bank doesn't need to send the private key out over the network, making it much more secure.

The most commonly used asymmetric encryption algorithm today is the RSA algorithm, invented in 1978 by Rivest, Shamir, and Adleman, all of whom were at MIT at the time.NET has the RSA algorithm as well, see the following example:

Encryption process:

private byte[] rsaCipherText;

private void mnuAsymmetricEncryption_Click(object sender, RoutedEventArgs e)

{

var rsa = 1;

// Encrypt the data.

var cspParms = new CspParameters(rsa);

cspParms.Flags = CspProviderFlags.UseMachineKeyStore;

cspParms. KeyContainerName = "My Keys";

var algorithm = new RSACryptoServiceProvider(cspParms);

var sourceBytes = new UnicodeEncoding(). GetBytes(myData);

rsaCipherText = algorithm.Encrypt(sourceBytes, true);

MessageBox.Show(String.Format("Data: {0}{1} Encrypted and Encoded: {2}",

myData, Environment.NewLine,

Convert.ToBase64String(rsaCipherText)));

}

Decryption process:

private void mnuAsymmetricDecryption_Click(object sender, RoutedEventArgs e)

{

if(rsaCipherText==null)

{

MessageBox.Show("Encrypt First!");

return;

}

var rsa = 1;

// decrypt the data.

var cspParms = new CspParameters (rsa);

cspParms.Flags = CspProviderFlags.UseMachineKeyStore;

cspParms.KeyContainerName = "My Keys";

var algorithm = new RSACryptoServiceProvider(cspParms);

var unencrypted = algorithm.Decrypt(rsaCipherText, true);

MessageBox.Show(new UnicodeEncoding().GetString(unencrypted));

}

While asymmetric encryption is secure, it is very slow compared to symmetric encryption, so we still have to use symmetric encryption to send the message, but the key used for symmetric encryption is one we can send through asymmetric encryption out. To explain the process, look at the following example:

(1) Alice needs to make a transaction at her bank's Web site, and her browser first generates a random number as a symmetric key.

(2) Alice's browser requests the public key from the bank's Web site.

(3) The bank sends the public key to Alice.

(4) Alice's browser encrypts her symmetric key using the bank's public key.

(5) Alice's browser sends the encrypted symmetric key to the bank.

(6) The bank decrypts Alice's browser's symmetric key using its private key.

(7) Alice and the bank can now use the symmetric key to encrypt and decrypt the communication.

(3) Summary

(1) Symmetric encryption encrypts and decrypts using the same key, so it's fast, but it's not as secure as it needs to transmit the key over the network.

(2) Asymmetric encryption uses a pair of keys, a public key and a private key, so it is highly secure, but encryption and decryption are slow.

(3) The solution is to encrypt the key of symmetric encryption using the public key of asymmetric encryption and send it out, the receiver uses the private key to decrypt to get the key of symmetric encryption, and then both parties can use symmetric encryption to communicate.

On the computer you can try Super Encryption 3000. with file encryption, folder encryption, data shredding, completely hide hard disk partitions, prohibit or read-only use of USB storage devices and other functions. Encryption speed block! And there are anti-copying anti-movement anti-deletion function. Every time you use the encrypted folder or encrypted files do not have to re-encrypt. And it is very easy to use, after installing the software directly on the need to encrypt the folder right-click, select Super Encryption or Folder Protection on it.