public bool Deposite(string token, double amount) { var username = cipher.Decrypt(token); if (authService.IsAuthenticate(username)) { var result = repo.Deposite(username, amount); if (result) { return(true); } throw new FaultException("Cannot deposite!"); } throw new FaultException("Not Authenticate!"); }
public async Task <string> DecryptAsync(string userId, string data) { var cypher = await strongKeyProvider.GetStrongKeyAsync(userId); var result = aes.Decrypt(cypher.Secret.ToUrlSafeBase64(), data); return(result); }
public async Task <DecryptedMessageDto> DecryptMessageAsync(MessageDto model) { var secretKey = await strongKeyProvider.GetStrongKeyAsync(model.Message.SenderId); string decryptedAesKey = aes.Decrypt(secretKey.Secret.ToUrlSafeBase64(), model.Message.CryptedAes); var session = await GetCurrentSessionAsync(model.Message.SenderId, model.Message.SessionId); if (rsa.VerifySignature(session.ClientPublicKey, model.Message.ObjectToBytes(), model.Sign.FromUrlSafeBase64())) { throw new ApiError(new ServerException("Incorrect signature")); } return(new DecryptedMessageDto() { MessageId = model.Message.MessageId, CryptedText = model.Message.CryptedText, Aes = decryptedAesKey, ReceiverId = model.Message.ReceiverId, SenderId = model.Message.SenderId }); }
public bool LogOut(string token) { string username = cipher.Decrypt(token); return(repo.LogOut(username)); }