public void DirectEncrypt() { var plainText = Encoding.UTF8.GetBytes("Hello world"); var iv = SomeBytes(16); var key = SomeBytes(32); var encrypted = CryptUtil.EncryptBytes(key, iv, plainText); var decrypted = CryptUtil.DecryptBytes(key, iv, encrypted); Check.That(decrypted).Equals(plainText); }
public void SaveFile(File file, FileStorages storage) { var crypt = new CryptUtil(Settings); file.Data.StoredData = EncryptFiles ? crypt.EncryptBytes(file.Data.StoredData) : file.Data.StoredData; file.Data.StoredThumbData = EncryptFiles ? crypt.EncryptBytes(file.Data.StoredThumbData) : file.Data.StoredThumbData; file._CreateDate = DateTime.Now; var oldfile = _context.Files.SingleOrDefault(f => f.FileUId == file.FileUId); if (oldfile == null) { _context.Files.Add(file); } else { _context.Files.Remove(oldfile); _context.Files.Add(file); } _context.SaveChanges(); _log.Log($"File '{file.FileUId}' was uploaded to folder '{file.Folder}'.", saveParameters: false); }
public void SaveFile(File file, FileStorages storage) { using (var context = new Data.CMSContext()) { file.Data.StoredData = EncryptFiles ? CryptUtil.EncryptBytes(file.Data.StoredData) : file.Data.StoredData; file.Data.StoredThumbData = EncryptFiles ? CryptUtil.EncryptBytes(file.Data.StoredThumbData) : file.Data.StoredThumbData; var oldfile = context.Files.SingleOrDefault(f => f.FileUId == file.FileUId); if (oldfile == null) { context.Files.Add(file); } else { context.Files.Remove(oldfile); context.Files.Add(file); } context.SaveChanges(); } }