Last active
April 20, 2026 20:22
-
-
Save marcinotorowski/6a51023600160fcceef9ceea341bbc4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using System.Security.Cryptography; | |
| using System.Text; | |
| namespace Otor | |
| { | |
| public class MsixUtils | |
| { | |
| public static string GetPublisherHash(string publisherId) | |
| { | |
| using var sha = HashAlgorithm.Create("SHA256"); | |
| var encoded = sha.ComputeHash(Encoding.Unicode.GetBytes(publisherId)); | |
| var binaryString = string.Concat(encoded.Take(8).Select(c => Convert.ToString(c, 2).PadLeft(8, '0'))) + '0'; // representing 65-bits = 13 * 5 | |
| var encodedPublisherId = string.Concat(Enumerable.Range(0, binaryString.Length / 5).Select(i => "0123456789abcdefghjkmnpqrstvwxyz".Substring(Convert.ToInt32(binaryString.Substring(i * 5, 5), 2), 1))); | |
| return encodedPublisherId; | |
| } | |
| } | |
| } |
Author
Thank you, it works for me!
Migrated to Python:
import hashlib
def calculate_publisher_hash(publisher_id):
encoded = hashlib.sha256(publisher_id.encode("utf-16-le")).digest()
binary_string = "".join(f"{b:08b}" for b in encoded[:8]) + "0" # 65 bits = 13 * 5
alphabet = "0123456789abcdefghjkmnpqrstvwxyz"
return "".join(
alphabet[int(binary_string[i * 5:(i + 1) * 5], 2)]
for i in range(len(binary_string) // 5)
)
It can also be done with the use of available APIs:
#include <appmodel.h>
HRESULT PublisherIdFromPublisher(
_In_ PCWSTR publisher,
_Out_writes_(PACKAGE_PUBLISHERID_MAX_LENGTH + 1) PWSTR publisherId)
{
PCWSTR name{ L"xyz" };
const size_t nameLength{ ARRAYSIZE(L"xyz") - 1 };
const size_t offsetToPublisherId{ name + 1 }; // xyz_...publisherid...
PACKAGE_ID id{};
id.name = name;
id.publisher = publisher;
WCHAR familyName[PACKAGE_PUBLISHERID_MAX_LENGTH + 1]{};
UINT32 n{ ARRAYSIZE(familyName) };
RETURN_IF_WIN32_ERROR(PackageFamilyNameFromId(&id, &n, familyName);
RETURN_IF_FAILED(StringCchCopyW(publisherId, PACKAGE_PUBLISHERID_MAX_LENGTH + 1, familyName + offsetToPublisherId));
return S_OK;
}
see: https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/package-identity-overview
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a compact algorithm that given a publisher ID calculates its hash for APPX-management purposes.
The algorithm:
0123456789abcdefghjkmnpqrstvwxyz(32 letters), wherenis the result of the previous operation.Steps 5 and 6 actually represent the Douglas Crockford Base32 algorithm
Sample input:
E=marcin@otorowski.com, CN=Marcin Otorowski, O=Marcin Otorowski, S=zachodniopomorskie, C=PLOutput:
zxq1da1qqbezeVerification: