[ Download Code ] | [ Download Help ]
Rather than going straight to the code to just show you how it's done, we're going to opt to explain some of these objects along with how to code. In this article, it’s assumed you know what regions are and you’re aware that comments are there to assist other developers in understanding the code.
Initialization Vector (IV):
A block of bits (64 for DES), that is combined with the first block of data depending on the mode of the encryption. Sometimes it is random, and it can also be sent with the encrypted outcome.
A secret block of bits used to encrypt. Depending on the type of encryption, the size of the blocks of bits may differ. The size of the Private-Key does not directly reflect the strength of the encryption. The specific algorithm mixed with the size of the Private-Key determines the overall strength of the encryption: for example, you may have a 192 bit Triple DES encryption, and it won’t be as secure as a 128 bit Rijndael encryption.
Basically different methods on how the blocks of data are processed. Often 64 to 128 bits, the mode determines the encryptions confidentiality and integrity.
A flow of data of some sort is considered a stream. The flow’s length may be undetermined, but it usually has an end.
A stream object that will read bytes is used commonly in byte-based encryption algorithms. It is commonly used with files, but may be used with any type of byte collection.
What are the Objects Used?
The objects used in this article are bytes, Encoding, Memory Streams, regular base streams, Cryptographic Transformations, Cryptographic Streams, and enumerators. For the most part, you should have a good grasp on some of these objects, but we’ll go over them briefly.
A byte is 8 bits. If that’s news to you, I suggest opening up a more beginner’s tutorial so you don’t get overwhelmed with information. For the rest of us, a byte is a small integer with a value between 0 and 255. A single character is usually calculated as one or two bytes depending on the language. A collection of bytes or a byte array is just what the name describes. It contains any number of bytes in a specified order.
Encoding objects are used to easily convert to different types. Typically used with base types such as Booleans (bits), bytes, integers, strings, and the rest of the common types we use everyday. The use of the encoding objects help keep our data integrity and give a forgiving method of translation rather than having a clutter of functions to manually do the conversions.
Memory Streams are found under the namespace System.IO, and has several overloaded constructors. Memory Streams differ from the normal stream object as it specifically uses RAM as a backing store instead of disk or network transfer.
A base Stream object is also found under the namespace System.IO, and is usually what most other streams are inherited from, and is an abstract base class. It’s and abstraction of a sequence of bytes of any sort.
Cryptographic Transformations are found under the namespace System.Security.Cryptography implementing the ICryptoTransform interface, and they are algorithms and processes stored to assist in ease of development.
Cryptographic Streams are found in System.Security.Cryptography, and are used by the common language runtime (CLR) of the .NET framework’s design for cryptography.
Enumerators are essentially a distinct type of named constants. Usually starts with values 0, but may be specifically created to start with any integer, it’s used primarily to add a language to the constant values.
With the basics out of the way, we can start looking into the underlying code to see how the Triple DES Encryption is implemented in our .NET applications.