static byte[] CreateKeyDigest(String password, byte[] docIdData)
{
Check16Bytes(docIdData, "docId");
int nChars = Math.Min(password.Length, 16);
byte[] passwordData = new byte[nChars * 2];
for (int i = 0; i < nChars; i++)
{
char ch = password[i];
passwordData[i * 2 + 0] = (byte)((ch << 0) & 0xFF);
passwordData[i * 2 + 1] = (byte)((ch << 8) & 0xFF);
}
byte[] kd;
MD5 md5 = new MD5CryptoServiceProvider();
byte[] passwordHash = md5.ComputeHash(passwordData);
md5.Clear();
md5.Initialize();
byte[] data=new byte[passwordHash.Length*16 + docIdData.Length*16];
int offset=0;
for (int i = 0; i < 16; i++)
{
Array.Copy(passwordHash, 0, data, offset, PASSWORD_HASH_NUMBER_OF_BYTES_USED);
offset+=passwordHash.Length;
Array.Copy(docIdData,0,data,offset,docIdData.Length);
offset += docIdData.Length;
}
kd = md5.ComputeHash(data);
byte[] result = new byte[KEY_DIGEST_LENGTH];
Array.Copy(kd, 0, result, 0, KEY_DIGEST_LENGTH);
return result;
}