1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-23 05:36:08 +03:00
ProxySU/ProxySuper.Core/Helpers/Utils.cs

46 lines
1.4 KiB
C#
Raw Normal View History

2021-05-16 04:12:47 +03:00
using Newtonsoft.Json;
using System;
2021-05-15 11:45:36 +03:00
using System.Collections.Generic;
2021-05-16 04:12:47 +03:00
using System.IO;
2021-05-15 11:45:36 +03:00
using System.Linq;
2021-05-16 04:12:47 +03:00
using System.Runtime.Serialization.Formatters.Binary;
2021-05-15 11:45:36 +03:00
using System.Text;
using System.Threading.Tasks;
namespace ProxySuper.Core.Services
{
2021-05-16 04:12:47 +03:00
public class Utils
2021-05-15 11:45:36 +03:00
{
2021-05-16 04:12:47 +03:00
public static string Base64Encode(string plainText)
2021-05-15 11:45:36 +03:00
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
2021-05-16 04:12:47 +03:00
public static string Base64Decode(string base64EncodedData)
2021-05-15 11:45:36 +03:00
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
2021-05-16 04:12:47 +03:00
public static T DeepClone<T>(T obj) where T : class
{
var serialized = JsonConvert.SerializeObject(obj);
return JsonConvert.DeserializeObject<T>(serialized);
}
2021-05-25 13:28:37 +03:00
public static string GetTickID()
{
return DateTime.Now.Ticks.ToString();
}
2021-06-29 12:43:48 +03:00
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
2021-05-15 11:45:36 +03:00
}
}