Signature.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ConsoleApp1.OCPPAuth
  8. {
  9. internal static class Signature
  10. {
  11. public static void Test()
  12. {
  13. string signature = GetSignature(
  14. timestamp: "1731483946",
  15. partnerid: "523E6CE1-8BA4-4D88-8895-AC05F5B3AE8F",
  16. saltkey: "L^u9d2Rt@C");
  17. }
  18. private static string GetSignature(string timestamp, string partnerid, string saltkey)
  19. {
  20. var unencodeText = $"{timestamp}{partnerid}{saltkey}".ToLower();
  21. var signature = GetSignature(unencodeText);
  22. return signature;
  23. }
  24. private static string GetSignature(string unencodeText)
  25. {
  26. if ((unencodeText == null) || (unencodeText.Length == 0))
  27. {
  28. return String.Empty;
  29. }
  30. unencodeText = unencodeText.ToLower();
  31. MD5 md5 = MD5.Create();// new MD5CryptoServiceProvider();
  32. byte[] textToHash = Encoding.UTF8.GetBytes(unencodeText);
  33. byte[] result = md5.ComputeHash(textToHash);
  34. return BitConverter.ToString(result).Replace("-", "").ToLower();
  35. }
  36. }
  37. }