add game manifest hash algorithm

This commit is contained in:
CroakFang
2022-12-13 23:09:47 +08:00
parent f942acb6ef
commit fd39c75a64
+23 -21
View File
@@ -3,31 +3,33 @@ using System;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
public class ManifestEntry
namespace Assets.Editor.RootMotion
{ {
public class ManifestEntry public static byte[] CalHame(ulong checksum, ulong size, byte[] name)
{ {
public static byte[] CalHame(ulong checksum, ulong size, byte[] name) if (name == null) return null;
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
byte[] allbyte = new byte[name.Length + 16];
byte[] checksumByte = BitConverter.GetBytes(checksum);
byte[] sizeByte = BitConverter.GetBytes(size);
for (int i = 0; i < 16; i++)
{ {
if (name == null) return null; allbyte[i] = (i < 8 ? checksumByte[7 - i] : sizeByte[15 - i]);
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
byte[] allbyte = new byte[name.Length + 16];
byte[] checksumByte = BitConverter.GetBytes(checksum);
byte[] sizeByte = BitConverter.GetBytes(size);
for(int i=0; i < 16; i++)
{
allbyte[i] = (i < 8 ? checksumByte[7 - i] : sizeByte[15 - i]);
}
Buffer.BlockCopy(name, 0, allbyte, 16, name.Length);
return sha1.ComputeHash(allbyte);
} }
Buffer.BlockCopy(name, 0, allbyte, 16, name.Length);
return sha1.ComputeHash(allbyte);
}
public static string CalHameString(ulong checksum, ulong size, byte[] name) public static string CalHameString(ulong checksum, ulong size, byte[] name)
{ {
var bytes = CalHame(checksum, size, name); var bytes = CalHame(checksum, size, name);
Base32 base32 = new Base32(); Base32 base32 = new Base32();
return base32.Encode(bytes); return base32.Encode(bytes);
} }
public static string CalHameString(ulong checksum, ulong size, string name)
{
return CalHameString(checksum, size, Encoding.UTF8.GetBytes(name));
} }
} }