public async Task SetRconPassword(string host) { var server = await _serverRepository.Find(Context.Guild.Id, host); if (server != null) { await ReplyAndDeleteAsync($"Check your DM's for information on how to set the password {Context.User.Mention}", timeout : TimeSpan.FromSeconds(10)); var msg = await Context.User.SendMessageAsync($"Type in the rcon password you wish to set for the `{server.Host}` server"); var response = await NextMessageAsync(new EnsureFromUserDmCriterion(msg.Channel, Context.User), TimeSpan.FromSeconds(30)); if (!string.IsNullOrWhiteSpace(response?.Content)) { server.RconPassword = EncryptionProvider.AESEncrypt(response.Content, _encryptionSettings.Key, _encryptionSettings.IV); var result = await _serverRepository.Save(server); if (result) { await Context.User.SendMessageAsync($"Rcon password for server `{server.Host}` has been saved"); return; } } await Context.User.SendMessageAsync($"Failed to save the password for the `{server.Host}` server"); } else { await ReplyAndDeleteAsync($"Could not find a server with host `{host}`", timeout : TimeSpan.FromSeconds(10)); } }
public void Test1() { const string original = "test string for encryption and decryption test"; var encrypted = EncryptionProvider.AESEncrypt(original, _key, _iv); Assert.NotNull(encrypted); Assert.IsNotEmpty(encrypted); var decrypted = EncryptionProvider.AESDecrypt(encrypted, _key, _iv); Assert.NotNull(decrypted); Assert.IsNotEmpty(decrypted); Assert.AreEqual(original, decrypted); }