CryptographyProvider.cs 975 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. }
  36. }