BDU/加密狗/加密狗驱动类.cs

112 lines
4.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace
{
public class
{
// 保留原有方法,但添加新方法
public static int (ushort Index, string , string )
{
// 保持不变
var re = API类.VikeyFind(out var );
if (re != 0) return -1;
API类.VikeyAdminLogin(Index, );
SHA256 sHA256 = SHA256.Create();
API类.VikeyGetHID(Index, out uint pid);
byte[] HID = BitConverter.GetBytes(pid);
var pswd = Encoding.UTF8.GetBytes();
byte[] = HID.Concat(pswd).ToArray();
var = sHA256.ComputeHash();
API类.VikeyWriteData(Index, 0, 32, );
byte[] randomBytes = new byte[96];
Random random = new Random();
random.NextBytes(randomBytes);
API类.VikeyWriteData(Index, 32, 96, randomBytes);
return 0;
}
/// <summary>
/// 新方法:仅检查加密狗时间,不验证密码和数据
/// </summary>
public static int ()
{
var re = API类.VikeyFind(out var );
if (re != 0 || == 0) return -1;
// 直接返回第一个找到的加密狗
return 0;
}
/// <summary>
/// 原有方法:寻找加密狗并进行完整验证
/// </summary>
public static int (string , string )
{
var re = API类.VikeyFind(out var );
if (re != 0) return -1;
int = -1;
for (ushort i = 0; i < ; i++)
{
re = API类.VikeyUserLogin(i, );
if ((i, )) return i;
}
return ;
}
public static bool (ushort Index, string )
{
// 保持不变
SHA256 sHA256 = SHA256.Create();
API类.VikeyGetHID(Index, out uint pid);
byte[] HID = BitConverter.GetBytes(pid);
var pswd = Encoding.UTF8.GetBytes();
byte[] = HID.Concat(pswd).ToArray();
var = sHA256.ComputeHash();
var buffer = new byte[32];
API类.VikeyReadData(Index, 0, 32, buffer);
return buffer.SequenceEqual();
}
public static TimeSpan (int )
{
ushort = (ushort);
// 尝试直接获取时间,不进行登录验证
// 如果API需要登录才能获取时间可能需要先进行简单登录
try
{
API类.VikeyGetTime(, out API类.SVikeyTime );
API类.VikeyGetValidTime(, out API类.SVikeyTime );
DateTime _到期时间 = new DateTime();
DateTime _现在时间 = new DateTime();
try
{
_到期时间 = new DateTime(.cYear, .cMonth, .cDay,
.cHour, .cMinute, .cSecond);
_现在时间 = new DateTime(.cYear, .cMonth, .cDay,
.cHour, .cMinute, .cSecond);
}
catch (Exception)
{
return new TimeSpan(59, 59, 59, 59, 59);
}
return _到期时间 - _现在时间;
}
catch
{
// 如果获取时间失败,返回零
return TimeSpan.Zero;
}
}
}
}