Last active
December 13, 2021 17:18
-
-
Save marcinotorowski/6a51023600160fcceef9ceea341bbc4a to your computer and use it in GitHub Desktop.
This file contains 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; | |
} | |
} | |
} |
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), wheren
is 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=PL
Output:
zxq1da1qqbeze
Verification: