using System.Security.Cryptography;
public static void Main()
Console.WriteLine("This fiddle will generate a hashed password. Then you should use it in your dbo.users table in SolidCP database for the user you want (e.g. serveradmin)");
Console.WriteLine("P.S. it should work for MSPControl as well, however, it is not tested");
Console.WriteLine(@"Please enter your SolidCP.CryptoKey (find it in C:\SolidCP\Enterprise Server\web.config):");
String UserInputCryptoKey = Console.ReadLine();
Console.WriteLine(@"Please enter your desired password:");
String UserInputPassword = Console.ReadLine();
Console.WriteLine(@"Your hashed password is:");
Console.WriteLine(CryptoUtils.Encrypt(UserInputPassword, UserInputCryptoKey));
Console.WriteLine(@"Run again if you need more hashed passwords.");
public static class CryptoUtils
static string EnterpriseServerRegistryPath = "SOFTWARE\\SolidCP\\EnterpriseServer";
public static string CryptoKey
return "dt52z07ehjw421tmt";
public static bool EncryptionEnabled
public static string Encrypt(string InputText, string InputCryptoKey = "")
if (string.IsNullOrEmpty(InputCryptoKey)) {
Password = InputCryptoKey;
RijndaelManaged RijndaelCipher = new RijndaelManaged();
byte[] PlainText = System.Text.Encoding.Unicode.GetBytes(InputText);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);
cryptoStream.Write(PlainText, 0, PlainText.Length);
cryptoStream.FlushFinalBlock();
byte[] CipherBytes = memoryStream.ToArray();
string EncryptedData = Convert.ToBase64String(CipherBytes);
public static string Decrypt(string InputText)
if (InputText == null || InputText == "")
string Password = CryptoKey;
RijndaelManaged RijndaelCipher = new RijndaelManaged();
byte[] EncryptedData = Convert.FromBase64String(InputText);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
MemoryStream memoryStream = new MemoryStream(EncryptedData);
CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
byte[] PlainText = new byte[EncryptedData.Length];
int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);
public static string SHA1(string plainText)
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
HashAlgorithm hash = new SHA1Managed();
byte[] hashBytes = hash.ComputeHash(plainTextBytes);
return Convert.ToBase64String(hashBytes);