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

StringExtensions..::..AsShaHash Method (String, HashMethod, Int32, AsHashSubsetLocation)

Generate hash of a given string using SHA methods

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

Syntax


public static string AsShaHash(
	string plainText,
	HashMethod hashing,
	int byteCount,
	AsHashSubsetLocation location
)

Parameters

plainText
Type: String
The text to compute the hash for
hashing
Type: System..::..HashMethod
the hashing method to use
byteCount
Type: Int32
Set the number of bytes to take from the hashed when generating the string
location
Type: Walter..::..AsHashSubsetLocation
set the location from where to take the value from

Return Value

Hash value of a given string

Remarks


If the byteCount is not valid for the size of the hasher the default will be returned, 1 byte are 2 characters

Examples


You can generate a hash from a string by converting the string and taking a number of characters of the plain string obfiuscating the password source
Make a password from a string
var creditCard="4500-000-000-000";
var password= creditCard.AsShaHash(HashMethod.SHA256, 8);
var encryptionHelper = new Walter.SymmetricEncryption(password);           
        ///
var cypher= encryptionHelper.EncryptString(plain);
if(string.IsNullOrEmpty(cypher)) 
{
throw new ApplicationException("Encryption generate null");
}
var copy= encryptionHelper.DecryptString(cypher);
        ///
if(!string.Equals(plain, copy, StringComparison.Ordinal)) 
{
throw new Exception($"Plain {plain} and copy {copy} should be the same");
}