WALTER | Workable Algorithms for Location-aware Transmission, Encryption Response

CheckSum..::..Generate Method (String)

Generates a cryptographic hash for a given string using the MD5 algorithm. This method is designed to convert the input text into a hash value represented as an integer. If the input string is null or empty, 0 will be returned.

Namespace:  Walter.Cypher
Assembly:  Walter.Cypher (in Walter.Cypher.dll)

Syntax


[MethodImplAttribute]
[FeatureTagsAttribute]
public static int Generate(
	string source
)

Parameters

source
Type: String
The input string to hash.

Return Value

An integer representing the MD5 hash of the input string, or 0 if the input is null or empty.

Remarks


This method utilizes the MD5 hashing algorithm to generate a hash value, providing a compact representation of the input text. While MD5 is suitable for generating unique keys and performing quick comparisons, it is not recommended for security-critical applications due to vulnerabilities that allow for hash collisions. For applications requiring higher security, consider using SHA-256 or other more secure hashing algorithms. The method's approach is similar to the mechanism used in the AsSqlChecksum(System.String) extension method but specifically employs cryptographic hashing to produce the hash value. Note: MD5 hashing can produce hash collisions and is not secure for cryptographic purposes in modern applications. It is suitable for scenarios where quick and non-secure hashing is acceptable. For configuring cryptographic algorithms in .NET, refer to: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/map-algorithm-names-to-cryptography-classes

Examples


Implement checksum validation data and allows you to ensure their integrity before accepting it.
Sample Test method
[TestMethod()]
   public void GenerateSymulateStringIntegretyTest()
   {
       const string manipolationChecked = "Select * from settings where [Administrator] = 1";
       var expect = CheckSum.Generate(manipolationChecked);

       string sqlInject = $"{manipolationChecked} or 1=1";

       var isSafe=CheckSum.Validate(manipolationChecked, expect);
       Assert.IsTrue(isSafe);

       var isWrong=CheckSum.Validate(sqlInject, expect);
       Assert.IsFalse(isWrong);
   }