2
0

CryptographyProvider.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5. using MediaBrowser.Model.Cryptography;
  6. namespace Emby.Common.Implementations.Cryptography
  7. {
  8. public class CryptographyProvider : ICryptographyProvider
  9. {
  10. public Guid GetMD5(string str)
  11. {
  12. return new Guid(GetMD5Bytes(str));
  13. }
  14. public byte[] GetMD5Bytes(string str)
  15. {
  16. using (var provider = MD5.Create())
  17. {
  18. return provider.ComputeHash(Encoding.Unicode.GetBytes(str));
  19. }
  20. }
  21. public byte[] GetSHA1Bytes(byte[] bytes)
  22. {
  23. using (var provider = SHA1.Create())
  24. {
  25. return provider.ComputeHash(bytes);
  26. }
  27. }
  28. public byte[] GetMD5Bytes(Stream str)
  29. {
  30. using (var provider = MD5.Create())
  31. {
  32. return provider.ComputeHash(str);
  33. }
  34. }
  35. public byte[] GetMD5Bytes(byte[] bytes)
  36. {
  37. using (var provider = MD5.Create())
  38. {
  39. return provider.ComputeHash(bytes);
  40. }
  41. }
  42. }
  43. }