RsaHelper.cs 894 B

1234567891011121314151617181920212223242526
  1. using Microsoft.IdentityModel.Tokens;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. namespace TEAMModelOS.SDK.Helper.Security.RSACrypt
  8. {
  9. public class RsaHelper
  10. {
  11. public static SigningCredentials GenerateSigningCredentials(string file)
  12. {
  13. var privateRSA = RSAUtils.FromPrivateKey(File.ReadAllText(file));
  14. var signingKey = new RsaSecurityKey(privateRSA);
  15. var signingCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.RsaSha256);
  16. return signingCredentials;
  17. }
  18. public static SecurityKey GenerateValidationKey(string file)
  19. {
  20. var publicRSA = RSAUtils.FromPublicKey(File.ReadAllText(file));
  21. var signingKey = new RsaSecurityKey(publicRSA);
  22. return signingKey;
  23. }
  24. }
  25. }