public async Task <ValidationResult> Handle(Command command, CancellationToken cancellationToken) { unitOfWork.BeginTransaction(); var result = await commandValidator.ValidateAsync(command); if (!result.IsValid) { return(result); } var hash = StringHash.GetHash(command.Password); var hashToString = StringHash.GetHashString(hash); await privateCertRepository.SetMasterKeyAsync(hashToString); var newPassphrase = Guid.NewGuid().ToString(); var passphraseEncrypted = StringCipher.Encrypt(newPassphrase, command.Password); await privateCertRepository.SetPassphraseAsync(passphraseEncrypted); unitOfWork.SaveChanges(); unitOfWork.CommitTransaction(); return(result); }
public async Task <ValidationResult> Handle(Command request, CancellationToken cancellationToken) { unitOfWork.BeginTransaction(); var result = await commandValidator.ValidateAsync(request, cancellationToken); if (!result.IsValid) { return(result); } var hash = StringHash.GetHash(request.Password); var hashToString = StringHash.GetHashString(hash); await privateCertRepository.SetMasterKeyAsync(hashToString); var passphrase = await privateCertRepository.GetPassphraseAsync(); var passphraseDecrypted = StringCipher.Decrypt(passphrase, request.CurrentPassword); var passphraseEncrypted = StringCipher.Encrypt(passphraseDecrypted, request.Password); await privateCertRepository.SetPassphraseAsync(passphraseEncrypted); unitOfWork.SaveChanges(); unitOfWork.CommitTransaction(); return(result); }