覆盖包库回传、任务下发、CDM 任务同步与报警采集,并为包/任务 ID 与上传文件名加上路径安全校验。 Co-authored-by: Cursor <cursoragent@cursor.com>
27 lines
794 B
C#
27 lines
794 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace MiGu.Server.Ota;
|
|
|
|
public static class OtaHash
|
|
{
|
|
/// <summary>与参考 OTA 工具一致:MD5 → Base64,并去掉 '-'。</summary>
|
|
public static string OfFile(string path)
|
|
{
|
|
using var fs = File.OpenRead(path);
|
|
var hash = MD5.HashData(fs);
|
|
return Convert.ToBase64String(hash).Replace("-", "", StringComparison.Ordinal);
|
|
}
|
|
|
|
public static string OfBytes(ReadOnlySpan<byte> bytes)
|
|
{
|
|
var hash = MD5.HashData(bytes);
|
|
return Convert.ToBase64String(hash).Replace("-", "", StringComparison.Ordinal);
|
|
}
|
|
|
|
public static string Short(string? hash, int len = 8)
|
|
{
|
|
if (string.IsNullOrEmpty(hash)) return "—";
|
|
return hash.Length <= len ? hash : hash[..len];
|
|
}
|
|
}
|