/// ---------------------------------------------------------------------------------------- /// <summary> /// Encrypt preferences using a password /// </summary> /// ---------------------------------------------------------------------------------------- // Encrypt preferences using a password public static byte[] EncryptDataUsingPassword(byte[] data, string password, bool passwordIsHash, SEBSettings.sebConfigPurposes configPurpose) { string prefixString; // Check if .seb file should start exam or configure client if (configPurpose == SEBSettings.sebConfigPurposes.sebConfigPurposeStartingExam) { // prefix string for starting exam: normal password will be prompted prefixString = PASSWORD_MODE; } else { // prefix string for configuring client: configuring password will either be hashed admin pw on client // or if no admin pw on client set: empty pw prefixString = PASSWORD_CONFIGURING_CLIENT_MODE; if (!String.IsNullOrEmpty(password) && !passwordIsHash) { //empty password means no admin pw on clients and should not be hashed //or we got already a hashed admin pw as settings pw, then we don't hash again password = SEBProtectionController.ComputePasswordHash(password); } } byte[] encryptedData = SEBProtectionController.EncryptDataWithPassword(data, password); // Create byte array large enough to hold prefix and data byte[] encryptedSebData = new byte[encryptedData.Length + PREFIX_LENGTH]; Buffer.BlockCopy(Encoding.UTF8.GetBytes(prefixString), 0, encryptedSebData, 0, PREFIX_LENGTH); Buffer.BlockCopy(encryptedData, 0, encryptedSebData, PREFIX_LENGTH, encryptedData.Length); return(encryptedSebData); }
public static byte[] EncryptDataUsingPassword(byte[] data, string password, bool passwordIsHash, SEBSettings.sebConfigPurposes configPurpose) { string s; if (configPurpose == SEBSettings.sebConfigPurposes.sebConfigPurposeStartingExam) { s = "pswd"; } else { s = "pwcc"; if (!string.IsNullOrEmpty(password) && !passwordIsHash) { password = SEBProtectionController.ComputePasswordHash(password); } } byte[] numArray1 = SEBProtectionController.EncryptDataWithPassword(data, password); byte[] numArray2 = new byte[numArray1.Length + 4]; Buffer.BlockCopy((Array)Encoding.UTF8.GetBytes(s), 0, (Array)numArray2, 0, 4); Buffer.BlockCopy((Array)numArray1, 0, (Array)numArray2, 4, numArray1.Length); return(numArray2); }