/// <summary> /// editing encrypted data by id /// </summary> /// <param name="input"></param> /// <returns></returns> public virtual async Task ReplaceEncryptDataAsync(UpdateInput input) { var entity = await sensitiveRepository.GetByIdAsync(Int64.Parse(input.Id)); if (entity == null) { throw new NotFoundException( $"Could not find data with ID {input.Id}."); } var encryptionKey = config.GetCurrentKey(); if (string.IsNullOrWhiteSpace(encryptionKey)) { throw new MissingEncryptionKeyException($"Could not retrieve {entity.EncryptionKeyName}."); } var newData = new SensitiveDataEntity { Id = Int64.Parse(input.Id), Data = dataProtector.Encrypt(encryptionKey, input.ClearText), EncryptionKeyName = config.CurrentKeyName }; sensitiveRepository.Update(newData); }
/// <summary> /// Send a clear text and encrypt and save in database /// </summary> /// <param name="cleartext">The data to protect</param> /// <returns>The ID of the projected blob</returns> public virtual async Task <EncryptedOutput> EncryptDataAsync(string cleartext) { var encryptionKey = config.GetCurrentKey(); if (string.IsNullOrWhiteSpace(encryptionKey)) { throw new MissingEncryptionKeyException("Could not retrieve Current Encryption Key."); } var data = new SensitiveDataEntity { EncryptionKeyName = config.CurrentKeyName, Data = dataProtector.Encrypt(config.GetCurrentKey(), cleartext) }; var savedId = sensitiveRepository.Add(data); return(new EncryptedOutput() { Id = savedId.ToString() }); }
public void Update(SensitiveDataEntity sensitiveDataEntity) { _context.SensitiveDataEntities.Update(sensitiveDataEntity); _context.SaveChanges(); }
public void Remove(SensitiveDataEntity sensitiveDataEntity) { _context.SensitiveDataEntities.Remove(sensitiveDataEntity); _context.SaveChanges(); }
public long Add(SensitiveDataEntity sensitiveDataEntity) { _context.SensitiveDataEntities.Add(sensitiveDataEntity); _context.SaveChanges(); return(sensitiveDataEntity.Id); }