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
Visual Basic |
Dim instance As ISecretProvider
Dim secrets As String()
Dim returnValue As Byte()
returnValue = instance.CalculateHash(secrets)
|
Syntax
Visual Basic |
Function CalculateHash ( _
secrets As String() _
) As Byte()
|
C# |
byte[] CalculateHash (
string[] secrets
)
|
C++ |
array<unsigned char>^ CalculateHash (
array<String^>^ secrets
)
|
J# |
byte[] CalculateHash (
String[] secrets
)
|
JScript |
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:
|
Copy Code |
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