public static string EncryptPassword(string passwd)
{
// Use standard VNC Server Key
byte[] rawKey = new byte[8];
rawKey[0] = 23;
rawKey[1] = 82;
rawKey[2] = 107;
rawKey[3] = 6;
rawKey[4] = 35;
rawKey[5] = 78;
rawKey[6] = 88;
rawKey[7] = 7;
// revert it
rawKey = FixDESBug(rawKey);
byte[] Passwd_Bytes = new byte[8];
if (passwd.Length >= 8)
{
Encoding.ASCII.GetBytes(passwd, 0, 8, Passwd_Bytes, 0);
}
else
{
Encoding.ASCII.GetBytes(passwd, 0, passwd.Length, Passwd_Bytes, 0);
}
// VNC uses DES, not 3DES as written in some documentation
DES des = new DESCryptoServiceProvider();
des.Padding = PaddingMode.None;
des.Mode = CipherMode.ECB;
ICryptoTransform enc = des.CreateEncryptor(rawKey, null);
byte[] passwd_enc = new byte[8];
enc.TransformBlock(Passwd_Bytes, 0, Passwd_Bytes.Length, passwd_enc, 0);
string ret = "";
for (int i = 0; i < 8; i++)
{
ret += passwd_enc[i].ToString("x2");
}
return ret;
}