Program.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using Microsoft.AspNetCore.DataProtection;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using Microsoft.Extensions.Logging;
  7. using StackExchange.Redis;
  8. namespace Redis
  9. {
  10. public class Program
  11. {
  12. public static void Main(string[] args)
  13. {
  14. // Connect
  15. var redis = ConnectionMultiplexer.Connect("localhost:6379");
  16. // Configure
  17. using (var services = new ServiceCollection()
  18. .AddLogging(o => o.AddConsole().SetMinimumLevel(LogLevel.Debug))
  19. .AddDataProtection()
  20. .PersistKeysToRedis(redis, "DataProtection-Keys")
  21. .Services
  22. .BuildServiceProvider())
  23. {
  24. // Run a sample payload
  25. var protector = services.GetDataProtector("sample-purpose");
  26. var protectedData = protector.Protect("Hello world!");
  27. Console.WriteLine(protectedData);
  28. }
  29. }
  30. }
  31. }