ISecretProvider.CalculateHash Method
Calculates a one-way hash that can be used to search for one-time passwords.
Namespace: Microsoft.Clm
Assembly: Microsoft.Clm.Common (in Microsoft.Clm.Common.dll)
Usage
'Usage
Dim instance As ISecretProvider
Dim secrets As String()
Dim returnValue As Byte()
returnValue = instance.CalculateHash(secrets)
Syntax
'Declaration
Function CalculateHash ( _
secrets As String() _
) As Byte()
byte[] CalculateHash (
string[] secrets
)
array<unsigned char>^ CalculateHash (
array<String^>^ secrets
)
byte[] CalculateHash (
String[] secrets
)
function CalculateHash (
secrets : String[]
) : byte[]
Parameters
- secrets
An array of String objects that contain one-time passwords. This array can be retrieved by calling the GetSecrets method.
Return Value
An array of bytes that contain a searchable hash value.
Example
In order for the implementation of the CalculateHash method to be compatible with the implementation of FIM CM version 1, it must replicate the default FIM CM implementation of this method. The following is sample code that demonstrates the default FIM CM implementation of the CalculateHash method:
public byte[] CalculateHash(string[] secrets)
{
byte[] hash = null;
MemoryStream stream = new MemoryStream(100);
ASCIIEncoding encoding = new ASCIIEncoding();
int length = 0;
for (int i = 0; i < secrets.Length; i++)
{
//secrets[i] = SanitizeSecret(secrets[i]); //Modifies the secrets array (reference)
//byte[] bytes = encoding.GetBytes(secrets[i]);
byte[] bytes = encoding.GetBytes(SanitizeSecret(secrets[i]));
stream.Write(bytes, 0, bytes.Length);
length += bytes.Length;
}
stream.SetLength(length);
stream.Seek(0, SeekOrigin.Begin);
SHA1 sha1 = SHA1.Create();
hash = sha1.ComputeHash(stream);
stream.Close();
return hash;
}
protected string SanitizeSecret(string secret)
{
string sanitized = null;
if (secret == null)
return null;
sanitized = secret.Trim().ToUpper();
sanitized = sanitized.Replace(" ", "");
sanitized = sanitized.Replace("-", "");
sanitized = sanitized.Replace("O", "0");
sanitized = sanitized.Replace("I", "1");
sanitized = sanitized.Replace("L", "1");
return sanitized;
}
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Development Platforms
Windows 2008 x64 Edition
Target Platforms
Windows XP SP3, Windows Vista SP1+, Windows 7, Windows Server 2008, Windows Server 2008 R2
Change History
See Also
Reference
ISecretProvider Interface
ISecretProvider Members
Microsoft.Clm Namespace
GetSecrets