public static string GetVAsByteArray(InstructorValidationData aV, string instructorPassword) { try { //Serialize var ser = Framework_Project.Serialization.SerializationHelper.Serialize(aV); //Add special string at loca{0-2} to check for description in the future temp_ser = ser; ser = "FCT" + ser; //compress before encryption is better to reduce size // var compressed = Framework_Project.Compression.CompressionHelper.Zip(ser); //Encrypt using student password string encrypted = AESGCM.SimpleEncryptWithPassword(ser, instructorPassword); int x; for (int i = 0; i < 100; i++) { x = i; } return(encrypted); } catch (Exception ex) { throw new Exception("[Exception: Cannot Create GetVAsByteArray in Exam Helper ] [inner: " + ex.ToString()); } }
public void EncryptAnswerandExplanation(string instructorPassword) { foreach (var q in QuestionsList) { q.Answer = AESGCM.SimpleEncryptWithPassword(q.Answer, instructorPassword); q.AnswerExplanation = AESGCM.SimpleEncryptWithPassword(q.AnswerExplanation, instructorPassword); } }
public void EncryptDetails() { StudentName = AESGCM.SimpleEncryptWithPassword(StudentName, ExamKey); StudentID = AESGCM.SimpleEncryptWithPassword(StudentID, ExamKey); SequenceNumber = AESGCM.SimpleEncryptWithPassword(SequenceNumber, ExamKey); if (SharedKeyIS != "" && SharedKeyIS != null) { SharedKeyIS = AESGCM.SimpleEncryptWithPassword(SharedKeyIS, SharedKeyIS); } ExamKey = AESGCM.SimpleEncryptWithPassword(ExamKey, ExamKey); }
/// <summary> /// write text into file named fileName /// </summary> /// <param name="fileName"></param> /// <param name="text"></param> public static async Task <bool> WriteFileContent(string fileName, string text) { // Create new file; do nothing if exists CreateFileAtRoot(fileName); string filePath = Path.Combine(_fileSystem.LocalStorage.Path, fileName); IFile file = await rootFolder.GetFileAsync(filePath); await file.WriteAllTextAsync(AESGCM.SimpleEncryptWithPassword(text, AESGCMKey)); //encrypt return(true); }
public static void ExportEmailFile() { int saveCount = 0; int fileCount = 0; Log.Append("Syncing email cache to server..."); // Remove all original files foreach (string path in Directory.GetFiles(cacheDirectoryPath, "*.cfg*")) { if (File.Exists(cacheDirectoryPath + "CacheDump/" + Path.GetFileName(path))) { File.Delete(cacheDirectoryPath + "CacheDump/" + Path.GetFileName(path)); } File.Move(path, cacheDirectoryPath + "CacheDump/" + Path.GetFileName(path)); } StringBuilder str = new StringBuilder(); foreach (Email email in EmailList) { str.Append("[EM_ID_]=" + email.ID); str.Append("||[EM_UI_]=" + email.UID); str.Append("||[EM_TO_]=" + email.To); str.Append("||[EM_FR_]=" + email.From); str.Append("||[EM_SU_]=" + email.Subject); str.Append("||[EM_MD_]=" + email.MailDate + Environment.NewLine); saveCount++; if (saveCount % MAX_EMAIL_COUNT == 0) { Saver.Save(AESGCM.SimpleEncryptWithPassword(str.ToString(), AESGCM.AES256Key), cacheDirectoryPath + "emailMaster_" + (++fileCount) + ".cfg"); str = new StringBuilder(); } } // Get remainder if (saveCount % MAX_EMAIL_COUNT != 0 && str.Length > 0) { Saver.Save(AESGCM.SimpleEncryptWithPassword(str.ToString(), AESGCM.AES256Key), cacheDirectoryPath + "emailMaster_" + (++fileCount) + ".cfg"); } GetEmailCounts(); Log.Append("Sync complete!"); }
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 void SaveExamToFile(Exam anExam, string studentPassword, string saveLocation) { 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; //compress before encryption is better to reduce size var compressed = Framework_Project.Compression.CompressionHelper.Zip(ser); //Encrypt using student password string encrypted = AESGCM.SimpleEncryptWithPassword(compressed, studentPassword); ByteArrayToFile(saveLocation, encrypted); } catch (Exception ex) { throw new Exception("[Exception: Cannot Create exam in Exam Helper SaveExamToFile] [inner: " + ex.ToString()); } }
public static void SaveSettings() { StringBuilder str = new StringBuilder(); // Save user data foreach (User user in UserList) { str.Append("[US_NA_]=" + user.Name); str.Append("||[US_DE_]=" + user.Department); str.Append("||[US_ID_]=" + user.UserID); str.Append("||[US_LP_]=" + user.LoginPassword); str.Append("||[US_PR_]=" + user.Privilege); str.Append("||[US_SE_]=" + (user.SyncEmails ? "1" : "0")); str.Append("||[US_LU_]=" + user.LastUpdateTime); str.Append("||[US_PT_]=" + user.ReceivingProtocol); str.Append("||[US_PO_]=" + user.ReceivingPort); str.Append("||[US_EM_]=" + user.Email); str.Append("||[US_PW_]=" + user.Password + Environment.NewLine); } str.Append(Settings.GetSaveSettingsStr()); Saver.Save(AESGCM.SimpleEncryptWithPassword(str.ToString(), AESGCM.AES256Key), settingsFilePath); }
public static string Encrypt(string content, SecureString password) { return(AESGCM.SimpleEncryptWithPassword(content, ConvertToUnSecureString(password))); }
/// <summary> /// Takes the given text and encrypts it using the given password. /// </summary> /// <param name="textToEncrypt">Text to encrypt.</param> /// <param name="encryptionPassword">Encryption password.</param> /// <returns>The encrypted text.</returns> public static string Encrypt( string textToEncrypt, string encryptionPassword) { return(AESGCM.SimpleEncryptWithPassword( textToEncrypt, encryptionPassword)); }
private static void TestLibraries(bool testCompression = true, bool testEncryption = true) { var myOrgMsg = "123456"; var encryptedx = AESGCM.SimpleEncryptWithPassword(myOrgMsg, "123456"); var decryptedx = AESGCM.SimpleDecryptWithPassword(encryptedx, "1234567"); try { Parallel.For(0, 1000000, i => { var v = new InstructorValidationData($"Std{i}", DateTime.Now, 10, 11); var serialized = SerializationHelper.Serialize <InstructorValidationData>(v); if (serialized == null) { throw new Exception("serialized==null"); } string compressedString = Framework_Project.Compression.CompressionHelper.Zip(serialized); if (compressedString == null) { throw new Exception("compressed==null"); } // string decompressed = Framework_Project.Compression.CompressionHelper.Unzip(compressedString); string encrypted = AESGCM.SimpleEncryptWithPassword(compressedString, $"Keyyy{i}"); if (encrypted == null) { throw new Exception("encrypted==null"); } string decrypted = AESGCM.SimpleDecryptWithPassword(encrypted, $"Keyyy{i}"); if (decrypted == null) { throw new Exception("decrypted==null"); } if (decrypted != compressedString) { throw new Exception("decrypted!=compressedString"); } if (!StructuralComparisons.StructuralEqualityComparer.Equals(decrypted, compressedString)) { throw new Exception("decryptedBytes!=compressed"); } string decompressed = Framework_Project.Compression.CompressionHelper.Unzip(decrypted); if (decompressed == null) { throw new Exception("decompressed==null"); } if (decompressed != serialized) { throw new Exception("decompressed != serialized"); } var deserialized = SerializationHelper.Deserialize <InstructorValidationData>(serialized); }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }