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)
Syntax
'Declaration
Function CalculateHash ( _
secrets As String() _
) As Byte()
'Usage
Dim instance As ISecretProvider
Dim secrets As String()
Dim returnValue As Byte()
returnValue = instance.CalculateHash(secrets)
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 CLM version 1, it must replicate the default CLM implementation of this method. The following is sample code that demonstrates the default CLM 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;
}
Platforms
Windows Server 2003 Enterprise/Data Center Edition SP1
See Also
Reference
ISecretProvider Interface
ISecretProvider Members
Microsoft.Clm Namespace
GetSecrets
.gif)
Send comments about this topic to Microsoft.
© 2007 Microsoft Corporation. All rights reserved.