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;
|
|
|
|
|
|
2017-07-22 19:27:41 +00:00
|
|
|
|
namespace Glove {
|
2017-05-08 21:06:17 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|