update Pilz.cryptography to net6.0
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Management;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
@@ -75,7 +76,7 @@ namespace Pilz.Cryptography
|
||||
|
||||
protected virtual string GenerateDefault()
|
||||
{
|
||||
return GenerateUniquieID<UniquieID>(currentSimpleID++.ToString());
|
||||
return Helpers.GenerateUniquieID<UniquieID>(currentSimpleID++.ToString());
|
||||
}
|
||||
|
||||
public virtual void GenerateIfNull()
|
||||
@@ -124,44 +125,6 @@ namespace Pilz.Cryptography
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
#region Statics for Generation
|
||||
|
||||
protected static string GenerateUniquieID<T>(string var)
|
||||
{
|
||||
var sn = TryGetSerialNumberOfFirstHardDrive();
|
||||
var dateTime = DateTime.UtcNow.ToString("yyyyMMddHHmmssfffffff");
|
||||
var type = typeof(T).ToString();
|
||||
var together = sn + dateTime + type + var;
|
||||
|
||||
var md5 = MD5.Create();
|
||||
var hash = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(together))).Replace("-", string.Empty);
|
||||
md5.Dispose();
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
private static string Win32_PhysicalMedia_SerialNumber = null;
|
||||
private static string TryGetSerialNumberOfFirstHardDrive()
|
||||
{
|
||||
if (Win32_PhysicalMedia_SerialNumber == null)
|
||||
{
|
||||
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
|
||||
var sn = string.Empty;
|
||||
|
||||
foreach (ManagementObject wmi_HD in searcher.Get())
|
||||
{
|
||||
if (string.IsNullOrEmpty(sn) && wmi_HD["SerialNumber"] != null)
|
||||
sn = wmi_HD["SerialNumber"].ToString().Trim();
|
||||
}
|
||||
|
||||
Win32_PhysicalMedia_SerialNumber = sn;
|
||||
}
|
||||
|
||||
return Win32_PhysicalMedia_SerialNumber;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static implicit operator string(UniquieID id) => id.ID;
|
||||
public static implicit operator UniquieID(string id) => new UniquieID() { ID = id };
|
||||
public static implicit operator UniquieID(int id) => new UniquieID() { ID = Convert.ToString(id) };
|
||||
|
||||
Reference in New Issue
Block a user