Guest User

Untitled

a guest
Jan 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. private static string Encode(string text)
  2. {
  3. byte[] bytes = StringConvertToBytes(text);
  4.  
  5. using (MemoryStream stream = new MemoryStream())
  6. {
  7. Write(stream, Compute<CriptoProvider1>(bytes));
  8. Write(stream, Compute<CriptoProvider2>(bytes));
  9.  
  10. return BytesConvertToString(stream.ToArray());
  11. }
  12. }
  13.  
  14. private static void Write(MemoryStream stream, byte[] hash)
  15. {
  16. stream.WriteByte(0);
  17. stream.Write(hash, 0, hash.Length);
  18. }
  19.  
  20. private static string BytesConvertToString(byte[] bytes)
  21. {
  22. return Convert.ToBase64String(bytes);
  23. }
  24.  
  25. private static byte[] StringConvertToBytes(string text)
  26. {
  27. return Encoding.Unicode.GetBytes(text);
  28. }
  29.  
  30. private static byte[] Compute<T>(byte[] bytes)
  31. where T : HashAlgorithm, new()
  32. {
  33. return (new T()).ComputeHash(bytes);
  34. }
Add Comment
Please, Sign In to add comment