Summary:Symmetric cryptography is helpful for mass encryption, yet scalcapacity and key management problems limit its use
Threats:Indevelopment leakage, information corruption, man-in-the-middle strikes, brute-pressure attacks

Symmetric cryptography, known likewise as secret crucial cryptography, is the use of a solitary shared trick to share encrypted information in between parties. Ciphers in this category are dubbed symmetric bereason you usage the same key to encrypt and to decrypt the information. In basic terms, the sender encrypts data making use of a password, and also the recipient should know that password to access the information.

You are watching: Symmetric encryption is used primarily to provide confidentiality.

Symmetric encryption is a two-way process. With a block of plaintext and also a offered essential, symmetric ciphers will certainly constantly produce the same ciphermessage. Likewise, making use of that exact same essential on that block of ciphermessage will certainly always create the original plainmessage. Symmetric encryption is advantageous for protecting information between parties through an establiburned mutual crucial and also is also frequently used to keep confidential data. For instance, ASP.NET uses 3DES to encrypt cookie information for a forms authentication ticket.


Table 4.2 mirrors the attributes of the symmetric encryption algorithms accessible in the .NET Framework. Although these algorithms work-related differently, the .NET Framejob-related offers a standardized model with the SymmetricAlgorithm abstract base class.


NameBlock SizeCipher ModesKey Lengths
DES64CBC, ECB, and also CFB56 bits
Triple DES (3DES)64CBC, ECB, and also CFBTwo or three 56-little keys
Rijndael (AES)128, 192, 256CBC and ECB128, 192, or 256
RC264CBC, ECB, and also CFB40, 48, 56, 64, 72,80, 88, 96, 104,112, 120, or 128 bits

In enhancement to offering accessibility to different encryption algorithms, the .NET Frameoccupational also allows you to customize the cipher settings, vital lengths, block sizes, and also padding mode, and other parameters. The cipher mode determines the cipher's mode of operation. Although the CipherMode enumeration has five various settings, just 3 are sustained with existing algorithms, as displayed in Table 4.2. The CipherMode alternatives are:

Electronic Codebook Mode (EBC) The simplest and fastest mode, EBC allows ciphermessage to be broken one block at a time and also permits for codebook compilation. Encrypted blocks deserve to be reput without affecting the entire message. This mode is advantageous just where performance is the greatest priority, at the expense of security.

Cipher Block Chaining Setting (CBC) This mode supplies an initialization vector (IV) to add feedago to the block transformation. This prevents the troubles seen with EBC mode. Decryption needs discovering the IV, but this is not a mystery and you can transmit it over an insecure connection.

Cipher Feedearlier Setting (CFB) Uses an IV as CBC does but works with partial blocks, making it well suited for encrypting streaming information.


TIP

Although the symmetric algorithms easily accessible via the .NET Framejob-related are all block ciphers, you deserve to access them with a stream-oriented architecture. However before, they are still block ciphers, and also you need to not confuse them via stream ciphers that are not always as secure.


You can check out a full implementation of all the symmetric algorithms and settings in action through the symmetric.aspx file discovered in the Ch04 catalog of the supplepsychological code download accessible at this book's Web website (www.syngress.com/solutions). Figure 4.1 shows an example of how this page looks.



DES and 3DES

The U.S. federal government occurred File Encryption Standard (DES) in 1977 as an main cryptography standard; it is still used widely. DES formed the basis of the first automated teller machine (ATM) individual identification number (PIN) code authentication and also till recent years existed as the primary authentication encryption approach for UNIX equipments. DES is a block cipher using a 64-little block size via a 56-bit vital length. In early 1990 it was prrange insufficiently secure provided current hardware capabilities and that it was possible to exhaust all potential DES vital combinations in much less than a day. Triple DES (additionally known as 3DES) arised to attend to DESs shortcomings. 3DES supplies standard DES encryption cycled over itself 3 times, through one cycle using a various collection of encryption tricks. This was a simple yet simple way to successfully boost the essential dimension from 56-little bit to 168-bit, hence boosting its security, yet it obviously takes three times much longer than DES to encrypt the data.

DES is most likely nearing the finish of its helpful life, and also 3DES is not as effective as other algorithms, but they both still conquer as the algorithms of choice. Many programmers feel even more comfortable making use of these algorithms because of their compatibility and also wide acceptance.


The .NET Framework-related offers access to these algorithms via the DESCryptoServiceProvider and TripleDESCryptoServiceProvider classes. Note that both of these classes are managed wrappers that call the uncontrolled Win32 CryptoAPI features. Figures 4.2 and 4.3 demonstrate the use of 3DES encryption.



*

*

TIP


DES does have some tricks that you have to stop because they are weak. In reality, tright here are 4 keys that develop the same subkeys in eincredibly round. This suggests that if you encrypt information via among these keys and then encrypt that encrypted information again through the exact same crucial, you will finish up via the original plainmessage message. In enhancement to these weak keys are 12 semi-weak tricks. Semi-weak secrets occupational in pairs, wbelow one key decrypts data encrypted through the initially. ASP.NET allows you to check for these with the IsWeakKey and IsSemiWeakKey methods. You can watch the actual resource code for the IsWeakKey strategy in Figure 4.4 and the IsSemiWeakKey approach in Figure 4.5.


*

TIP

You can downfill the resource code for the .NET Framejob-related cryptography base classes at www.gotdotnet.com/team/clr/samples/eula_clr_cryptosrc.aspx.


Keep in mind that automatically created tricks and also those from the GenerateKey technique will certainly never create weak keys, and the opportunities of randomly selecting among these are 1 in 18,014,398,509,482,000. Furthermore, the DES and TripleDES classes will throw a CryptographicException if you try to use a weak vital.

Rijndael

Given that DES is reaching the end of its beneficial life and also 3DES is really not a lot even more than a short-term deal with, many experts are looking to other algorithms. The National Institute of Standards and also Technology (NIST) newly decided the Rijndael specification as its main replacement to DES. This specification, described as the State-of-the-art Encryption Standard (AES), deserve to be discovered at http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf. Rijndael supports bigger essential sizes than DES yet has actually improved performance over 3DES. The Rijndael specification supports crucial sizes of 128, 192, or 256 bits.


Due to the fact that of federal government standardization on this algorithm, it is supposed to become a widely supplied replacement for DES, although ASP.NET still relies greatly on DES and also 3DES. However before, Rijndael is the default algorithm offered with the SymmetricAlgorithm class and is the only symmetric algorithm that totally runs in controlled code. Figures 4.6 and 4.7 present an example using Rijndael encryption in ASP.NET. Keep in mind that Rijndael encryption does not have any kind of known weak keys and therefore does not assistance the IsWeakKey technique.


The Rijndael cipher is the fastest and supports the largest key size of all the .NET Framework-related ciphers.

RC2

RC2 is a symmetric block cipher designed by Ronald Rivest of RSA. RSA designed RC2 as a straight replacement for DES, improving on the performance and providing a variable vital size. RC2 is generally provided in S/MIME secure email and also is said to be two to three times as quick as DES. The finish RC2 specification is obtainable at www.ietf.org/rfc/rfc2268.txt. Figure 4.8 and Figure 4.9 show examples using RC2 encryption. Like Rijndael, RC2 does not have actually any kind of recognized weak tricks and also therefore does not support the IsWeakKey method.


RC2 is a commonly supplied algorithm that allows a variety of key lengths, but you must be aware that security experts consider RC2 with smaller keys to be insecure. You should always use a 128-bit vital, the maximum size available.

Selecting an Algorithm

Selecting a symmetric encryption algorithm is fundamentally a issue of vital size, compatibility, performance, experience, and individual preference. It is exceptionally challenging to prove that an encryption algorithm is the the majority of secure, although the faientice to demonstrate vulnerabilities over time is generally great enough proof. At some point, the toughness of the algorithm is based upon the size of the vital, but tbelow is no guarantee that any type of certain algorithm is without fregulations.


WARNING

At the moment of this creating, tbelow are no well-known fregulations with these algorithms, other than restrictions on crucial length. However before, we perform understand that some federal government agencies spend an excellent amount of money and also initiative searching for fregulations in these algorithms. If such an company were ever before to find (or currently has discovered) a flaw, you have the right to bet that would come to be one of their many carefully guarded secrets. In reality, they would likely go to excellent lengths to provide the impression that they have actually no clue of any flaws with the algorithms.


In a situation in which protection is a much greater priority than performance, you can avoid expocertain by layering multiple algorithms as presented in Figures 4.10 and 4.11. Since CryptoStreams permit chaining, it is a simple procedure to administer multiple layers of encryption.


Establishing Keys and Initialization Vectors

A variety of parameters recognize the outcome of the ciphertext. To decrypt the ciphermessage, you need to usage the exact same algorithm and the exact same parameters. Two of the parameters you should deliberately readjust each time are the crucial and the initialization vector (IV). The vital is the key essential to ensuring the integrity of the information and also the IV ensures randomness and also uniqueness of the ciphertext blocks.

If you encrypt data with the same key each time, you will constantly end up through the same ciphermessage. Knowing this, an attacker deserve to eventually gain sufficient data to decode many type of messperiods. To prevent this, the symmetric encryption algorithms usage the IV to initialize the procedure, ensuring a unique ciphertext message. The message recipient have to understand both the essential and also the IV to decrypt the message, yet just the vital must reprimary trick.


WARNING

When producing an essential and also IV, never derive one from the various other, because learning the IV might allow the attacker to identify the crucial. Also be certain to protect against a resolved IV for all encryption. The ideal solution is to usage the random IV that the algorithm immediately creates once it's initialized.


There are some challenges when it pertains to exchanging keys, especially once it involves sharing a crucial without any prior common keys. The totality reason for the encryption is that you execute not trust the transmission tool. Because of this, you have to somejust how transmit the essential over an insecure connection, but if you currently have a secure connection, why would certainly you require additionally encryption? Suppose, for example, that you want to sfinish someone an encrypted message. The recipient will certainly not have the ability to check out your message unmuch less you give her the correct crucial. It provides no sense to send the essential together with the message, so you rather contact the recipient on the phone to convey the key. But given that you currently trust the phone line sufficient to share the vital, you might too go ahead and also share the whole message. This is a significant shortresulting symmetric cryptography yet is an issue we deserve to get rid of through vital exadjust algorithms and also by making use of asymmetric cryptography. For an ASP.NET application, this is not as excellent an concern, bereason you deserve to easily use SSL to develop a secure session.

Many often you will certainly use symmetric encryption for conserving sensitive settings or user information. The trouble via this is that your ASP.NET application need to understand the vital and therefore must conserve the vital for its very own usage. This is a problem because if an attacker takes over the application, the attacker will acquire access to the application's secrets. For instance, ASP.NET uses the machine.config file to keep the encryption keys for many kind of encryption operations, such as encrypting a creates authentication ticket. If an attacker were able to check out this file, that attacker could create his very own authentication tickets. To aid this instance, you deserve to usage DPAPI, as defined later on in this chapter. You should additionally design your application so that it allows you to frequently readjust your tricks.

Sometimes you can desire the user to have the ability to encrypt indevelopment that also you cannot access. The user gives the crucial and also then gains accessibility to the encrypted information. However, it usually is not practical to suppose a user to memorize or type a large encryption key. If users have concerns remembering a password of six or eight personalities, just how will they remember a 128-little bit key? The solution is to allow the user to enter a password that you usage to derive an appropriate vital.


The PasswordDeriveBytes.CryptDeriveKey method deserve to develop an correct vital based upon a password, salt, algorithm, and also variety of iterations. This method creates a hash of the password making use of the gave salt and also uses that hash to develop one more hash, repeating this procedure for as many kind of iterations stated. The outcome is a lengthy string suitable to use as a crucial. Figures 4.12 and 4.13 show the code to usage CryptDeriveKey, and also Figure 4.14 mirrors an example key obtained from a user's password.


Figure 4.12. Using CryptDeriveKey: C#


Figure 4.13. Using CryptDeriveKey: VB.NET


Figure 4.14. Example of Key Derived from a Password


WARNING

Keep in mind that although you have the right to use CryptDeriveKey to rotate a brief password right into a strong key, save in mind that the vital is only as solid as the password itself. By using CryptDeriveKey, you are successfully reducing the key toughness to that of the password, not the various other means approximately. However, using a huge number of iterations definitely will slow-moving a brute-pressure attack because the attacker would have to perform those iterations for each password attempt. For a password-cracking tool, every millisecond makes a vast distinction.


When using CBC or CFB modes, you need to set an initialization vector. The IV functions favor a salt to additionally transdevelop the information so that 2 plaintext messperiods encrypted with unique IVs will develop distinct ciphermessage data. This provides it even more tough to perdevelop a dictionary strike on the ciphermessage. Typically you want to usage a random number for the IV, which SymmetricAlgorithm instantly generates as soon as the class is produced. You need to review this building and also save the IV so that you deserve to later decrypt the ciphermessage. If you create your very own IV, you need to create one that is the very same length as the vital. Keep in mind that the IV is not a mystery and also you perform not must take distinct measures to protect it. Figures 4.15 and 4.16 display examples of just how you have the right to appfinish the IV and the ciphermessage so that you deserve to keep them together. They additionally display exactly how you can extract the IV and also decrypt the ciphertext.


Symmetric cryptography does have its limitations and also weaknesses, yet it also plays an important function in protecting information. The .NET Framework gives excellent assistance for well-establiburned symmetric ciphers, and you must constantly encrypt sensitive data. Establish a solid structure for encryption beforehand in your application style.

Security Policies

Use strong symmetric ciphers to ensure the privacy of data.

Never rely on XOR, ROT-13, base-64 encoding, or any kind of homegrvery own encryption or obfuscation algorithm.

Avoid using DES unmuch less absolutely essential for backward compatibility; consider 3DES as a compatible alternative.

Use Rijndael/AES encryption for the ideal security and performance.

If using RC2 encryption, usage 128-little bit secrets whenever possible.

See more: Rk Motor 3700 N Holton St Milwaukee, 3700 N Holton St,53212, R K Motors Reviews, Ratings

When protection is a high priority and also performance a low priority, think about layering encryption algorithms.