public static AESEncryptionWrapper getInstance() { if (instance == null) { instance = new AESEncryptionWrapper(); } return(instance); }
public User(string userName, string userPass, string RoleName, Classification classification = Classification.None) { this.userName = userName; this.userPass = userPass; this.classification = classification; this.userRole = new Role(RoleName); this.userKeys = AESEncryptionWrapper.getInstance().generateKeyAndVector(); }
public override void Encrypt(byte[] key, byte[] iv, string encryptData = null) { try { var input = System.IO.File.ReadAllText(this.filePath); byte[] encryptedBytes = AESEncryptionWrapper.getInstance().EncryptStringToBytes(input, key, iv); var cypherText = Convert.ToBase64String(encryptedBytes); System.IO.File.WriteAllText(this.filePath, cypherText); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message + " ההצפנה נכשלה מהסיבה", "תקלה", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
public override void Decrypt(byte[] key, byte[] iv) { try { var input = System.IO.File.ReadAllText(this.filePath); var inputInBytes = Convert.FromBase64String(input); string descryptedtext = AESEncryptionWrapper.getInstance().DecryptStringFromBytes(inputInBytes, key, iv); System.IO.File.WriteAllText(this.filePath, descryptedtext); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message + " הפענוח נכשל מהסיבה", "תקלה", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }