programming4us
programming4us
SECURITY

Programming Hashing Algorithms (part 1) - The HashAlgorithm Class

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
The .NET Framework represents all hashing algorithms with the abstract System.Security.Cryptography.HashAlgorithm class. An abstract class represents each specific algorithm, extended by individual implementation classes, as shown in Figure 1. This approach supports selecting between several implementations of the same algorithm.
Figure 1. The .NET Framework class hierarchy for hashing algorithms

There are two types of implementation class included with the .NET Framework. Those whose names end with Managed (for example, SHA1Managed) were written in a managed .NET language (for example, C# or Visual Basic .NET). Those classes whose names end in CryptoServiceProvider (for example, SHA1CryptoServiceProvider) rely on the Windows Crypto API. Where there is a choice between a managed implementation and a Crypto API implementation, our (unscientific) testing shows that the Crypto API versions are slightly faster and consume less system memory.

Sidebar 2. The Windows Crypto API

The Crypto API is a component of the Windows operating system that contains cryptographic functionality. Many of the .NET cryptographic classes rely on features of the Crypto API for tasks such as key management or providing implementations of algorithms. As a .NET programmer, you do not need to have an understanding of the details of the Crypto API. We do not explore the Crypto API in this book; for more information, consult the Windows API documentation.


1. The HashAlgorithm Class

The design of the HashAlgorithm class makes it very simple to generate hash codes for any of the hashing algorithms that the .NET Framework supports. In this section, we show you how to create an instance of a given hashing algorithm and the techniques used to create hash codes for different types of data. Table 1 lists the members of the HashAlgorithm class.

Table 1. Members of the HashAlgorithm Class
Member Description
Properties  
Hash This property returns the value of the computed hash code. It is not commonly used. See the following sections for instructions on using the ComputeHash method to create hash codes.
HashSize This property returns the size of the hash code (in bits) that the hashing algorithm produces.
CanReuseTransform These properties are from the ICryptoTranform interface, which is not directly related to hashing, but is implemented by the HashAlgorithm class.
CanTransformMultipleBlocks  
InputBlockSize  
OutputBlockSize  
Methods  
Create This static method creates a new instance of the HashAlgorithm class by name. See Section 13.2.2 for further details.
ComputeHash The ComputeHash method is used to create hash codes from byte arrays and data streams. See Section 13.2.3 and Section 13.2.4 in this chapter for full details.
Initialize This is used by algorithm-implementation classes to initialize their state before use.
Clear This releases the resources held by the HashAlgorithm instance.
TransformBlock These methods are from the ICryptoTransform interface, which is not directly related to hashing, but is implemented by the HashAlgorithm class.
TransformFinalBlock  


Other  
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
REVIEW
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Celebrity Style, Fashion Trends, Beauty and Makeup Tips.
programming4us
 
 
programming4us