programming4us
programming4us
SECURITY

Hashing Algorithms: Extending the .NET Framework (part 1)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1. The Alder32 Algorithm Explained

The Adler32 algorithm generates a 32-bit hash code and is included as part of GZIP-compressed files to guard against inadvertent modification (for example, errors introduced in copying a compressed file over a network connection).

Adler32 is a simple algorithm, which operates on 8-bit blocks of message data to create hash codes, as follows:

  1. Define a 16-bit value called Sum1 with an initial value of 1.

  2. Define a 16-bit value called Sum2 with an initial value of 0.

  3. Process each 8-bit message block in turn:

  4. Add the numeric value of the message block to Sum 1, modulo 65521.

  5. Add the value of Sum 1 to Sum 2, modulo 65521.

  6. Concatenate Sum 2 and Sum 1 together to create a 32-bit hash code.

The Adler32 algorithm is not suitable for cryptographic uses because it produces hash codes that are susceptible to attack. Adler32 produces short hash codes that easily succumb to birthday attacks and, more importantly, it is easy to generate a message that results in a specific Adler32 hash code.


2. Defining the Abstract Class

The first step is to create an abstract class representing the Adler32 algorithm. The abstract class extends the System.Security.Cryptography.HashAlgorithm class but does not need to implement any members. Here is the definition of the abstract Adler32 algorithm class:

# C#
using System.Security.Cryptography;

public abstract class Adler32 : HashAlgorithm {

}

# Visual Basic .NET

Imports System.Security.Cryptography

Public MustInherit Class Adler32
Inherits HashAlgorithm

End Class

We have created the abstract class to conform to the .NET class model, allowing you to add other Adler32 implementations in the future. You can omit the abstract class, but we feel that the extra flexibility of this model is well worth the effort.

3. Defining the Implementation Class

The abstract HashAlgorithm class contains a lot of functionality that makes writing a new algorithm a simple process. For example, the details of the ComputeHash method are hidden from the implementer, and only a small number of methods need to be written in order to create a fully functional implementation.

3.1. Creating the implementation class

We have named our implementation class Adler32Managed, because it is written using a managed .NET language. The following listing shows the initial version of the implementation class extending the abstract Adler32 class. We have defined the two 16-bit values as o_sum_1 and o_sum_2. For Visual Basic .NET, we have used 32-bit integers to represent the 16-bit sums, because Visual Basic .NET does not support unsigned data types:

# C#

using System;
using System.Security.Cryptography;

public class Adler32Managed : HashAlgorithm {
private ushort o_sum_1;
private ushort o_sum_2;

}

# Visual Basic .NET
Imports System
Imports System.Security.Cryptography

Public Class Adler32Managed
Inherits Adler32

Private o_sum_1 As Integer
Private o_sum_2 As Integer

End Class

3.2. Implementing the Initialize method

You should use the Initialize method to set the initial state of any algorithm; an algorithm will produce unexpected hash code values unless correctly reset between invocations. For Adler32, we use this method to set the initial sum values. We have also added a class constructor that calls the Initialize method to ensure that the values are correctly set before the class is first used:

# C#

using System;
using System.Security.Cryptography;

public class Adler32Managed : HashAlgorithm {
private ushort o_sum_1;
private ushort o_sum_2;

public Adler32Managed( ) {
Initialize( );
}

public override void Initialize( ) {
// reset the sum values
o_sum_1 = 1;
o_sum_2 = 0;

}

# Visual Basic .NET

Imports System
Imports System.Security.Cryptography

Public Class Adler32Managed
Inherits Adler32

Private o_sum_1 As Integer
Private o_sum_2 As Integer

Public Sub New( )
Initialize( )
End Sub

Public Overrides Sub Initialize( )
' reset the sum values
o_sum_1 = 1
o_sum_2 = 0
End Sub

End Class

Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us