sockscape/server/Libraries/Square/CryptoExtensions.cs

29 lines
819 B
C#
Raw Normal View History

2017-05-08 21:06:17 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Square {
public static class CryptoExtensions {
2017-05-20 23:33:39 +00:00
public static byte[] SHA1(this string str)
=> Encoding.UTF8.GetBytes(str).SHA1();
2017-05-08 21:06:17 +00:00
2017-05-09 12:22:04 +00:00
public static byte[] SHA1(this byte[] bytes) {
2017-05-08 21:06:17 +00:00
using(var hasher = new SHA1CryptoServiceProvider()) {
2017-05-09 12:22:04 +00:00
return hasher.ComputeHash(bytes);
2017-05-08 21:06:17 +00:00
}
}
2017-05-20 23:33:39 +00:00
public static byte[] MD5(this string str)
=> Encoding.UTF8.GetBytes(str).MD5();
2017-05-09 12:22:04 +00:00
public static byte[] MD5(this byte[] bytes) {
2017-05-08 21:06:17 +00:00
using(var hasher = new MD5CryptoServiceProvider()) {
2017-05-09 12:22:04 +00:00
return hasher.ComputeHash(bytes);
2017-05-08 21:06:17 +00:00
}
}
}
}