public ExaminationStudentsFilter(FilterationSecurityLevel securityLevel, string examKey, string instPassword, SortedList <string, ExaminationFilterRule> rules = null) { SecurityLevel = securityLevel; ExamKey = examKey; InstructorPassword = instPassword; Rules = rules; }
public static bool ValidateExamCopy(string examCopy, string studentPassword, Logger aLogger, string sharedKeyIS, FilterationSecurityLevel secLevel, string SequenceNumberOriginal) { try { var x = GetExamFromByteArray(examCopy, studentPassword, sharedKeyIS, secLevel); long orgSN = long.Parse(SequenceNumberOriginal); long newSN = long.Parse(x.RequiredStudentDetails.SequenceNumber); if (orgSN == newSN - 1) { aLogger.LogMessage("[Correct Sequence Number ::: Exam Validated Correctly]", LogMsgType.Verbose); return(true); } else { aLogger.LogMessage($"[Incorrect Sequence Number ::: Wrong Exam ... OriginalSN:[{SequenceNumberOriginal}], ReceivedSN:[{x.RequiredStudentDetails.SequenceNumber}]", LogMsgType.Verbose); return(false); } } catch (Exception ex) { aLogger.LogMessage("INVALID EXAM FILE OR PASSWORD:" + ex.ToString(), LogMsgType.Error); return(false); } }
private SortedList <int, ExaminationStudentsFilter> GetFirewalls(int numberofStdsInit, int MaxStdNum, string studentPassword, string instructorPassword, int step, FilterationSecurityLevel secLevel) { SortedList <int, ExaminationStudentsFilter> ret = new SortedList <int, ExaminationStudentsFilter>(); Parallel.ForEach(BetterEnumerable.SteppedRange(numberofStdsInit, MaxStdNum, step), (index) => { SortedList <string, ExaminationFilterRule> rules = new SortedList <string, ExaminationFilterRule>(); for (int i = 0; i < index; i++) { rules.Add($"Std{i}", new ExaminationFilterRule { StdID = $"Std{i}", StdName = $"StdName{i}", AllowSpecificIPs = false, AllowedIPs = new List <string> { "ANY", }, SharedKeyIS = $"Keyyyyyyy{i}", }); } lock (ret) { ret.Add(index, new ExaminationStudentsFilter(secLevel, studentPassword, instructorPassword, rules)); } }); return(ret); }
public static Exam GetExamFromByteArray(string encryptedFile, string examKey, string sharedKeyIS, FilterationSecurityLevel secLevel) { string decrypted; if (secLevel == FilterationSecurityLevel.Moderate) { decrypted = AESGCM.SimpleDecryptWithPassword(encryptedFile, examKey); } else { decrypted = AESGCM.SimpleDecryptWithPassword(encryptedFile, sharedKeyIS); } //unzip if (decrypted == null) { int x = 10; } var unzippedFile = Framework_Project.Compression.CompressionHelper.Unzip(decrypted); if (unzippedFile.Substring(0, 3) != "FCT") { throw new InvalidStudentPasswordException("In GetExamFromFile"); } unzippedFile = unzippedFile.Substring(3, unzippedFile.Length - 3); try { var exmp = Framework_Project.Serialization.SerializationHelper.Deserialize <Exam>(unzippedFile); return(exmp); } catch (Exception ex) { throw new Exception("in GetExamFromFile, cannot cast the XML to Exam Class. "); } }
public static Exam GetExamFromString(string zippedFile, string studentPassword, string sharedKeyIS, FilterationSecurityLevel secLevel) { //string byteArray = ""; // int indexBA = 0; // foreach (char item in zippedFile.ToCharArray()) // { // byteArray[indexBA++] = (byte)item; // } return(GetExamFromByteArray(zippedFile, studentPassword, sharedKeyIS, secLevel)); }
public static Exam GetExamFromFile(string fileLocation, string studentPassword, string sharedKeyIS, FilterationSecurityLevel secLevel) { //Get byte array from file name //var encrypted = GetExamFileAsBytes(fileLocation); var encrypted = File.ReadAllText(fileLocation); return(GetExamFromByteArray(encrypted, studentPassword, sharedKeyIS, secLevel)); }
public static string GetExamFileWithoutSave(Exam anExam, string examKey, string sharedKeyIS, FilterationSecurityLevel secLevel) { try { //Serialize var ser = Framework_Project.Serialization.SerializationHelper.Serialize(anExam); //Add special string at loca{0-2} to check for description in the future temp_ser = ser; ser = "FCT" + ser; if (secLevel == FilterationSecurityLevel.Moderate) { //compress before encryption is better to reduce size var compressed = Framework_Project.Compression.CompressionHelper.Zip(ser); //Encrypt using Exam Key var encrypted = AESGCM.SimpleEncryptWithPassword(compressed, examKey); return(encrypted); } else if (secLevel == FilterationSecurityLevel.High) //REMOVE DOUBLE ENCRYPTION FROM ALGO IN PAPER { //compress before encryption is better to reduce size var compressed = Framework_Project.Compression.CompressionHelper.Zip(ser); //Encrypt using student password SharedKeyIS var encrypted = AESGCM.SimpleEncryptWithPassword(compressed, sharedKeyIS); return(encrypted); } return(null); } catch (Exception ex) { throw new Exception("[Exception: Cannot Create exam in Exam Helper SaveExamToFile] [inner: " + ex.ToString()); } }
public static bool ValidateExamCopy(string examCopy, string studentPassword, string sharedKeyIS, FilterationSecurityLevel secLevel) { try { var x = GetExamFromByteArray(examCopy, studentPassword, sharedKeyIS, secLevel); return(true); } catch (Exception ex) { return(false); } }