public static void ResolvePayloadInfo(IPayloadInfo payloadInfo) { if (String.IsNullOrEmpty(payloadInfo.SourceFile)) { return; } FileInfo fileInfo = new FileInfo(payloadInfo.SourceFile); if (null != fileInfo) { payloadInfo.FileSize = (int)fileInfo.Length; payloadInfo.Hash = Common.GetFileHash(fileInfo); // Try to get the certificate if payloadInfo is a signed file and we're not suppressing signature validation for payloadInfo payload. X509Certificate2 certificate = null; try { if (!payloadInfo.SuppressSignatureValidation) { certificate = new X509Certificate2(fileInfo.FullName); } } catch (CryptographicException) // we don't care about non-signed files. { } // If there is a certificate, remember its hashed public key identifier and thumbprint. if (null != certificate) { byte[] publicKeyIdentifierHash = new byte[128]; uint publicKeyIdentifierHashSize = (uint)publicKeyIdentifierHash.Length; Microsoft.Tools.WindowsInstallerXml.Cab.Interop.NativeMethods.HashPublicKeyInfo(certificate.Handle, publicKeyIdentifierHash, ref publicKeyIdentifierHashSize); StringBuilder sb = new StringBuilder(((int)publicKeyIdentifierHashSize + 1) * 2); for (int i = 0; i < publicKeyIdentifierHashSize; ++i) { sb.AppendFormat("{0:X2}", publicKeyIdentifierHash[i]); } payloadInfo.PublicKey = sb.ToString(); payloadInfo.Thumbprint = certificate.Thumbprint; } } FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(payloadInfo.SourceFile); if (null != versionInfo) { // Use the fixed version info block for the file since the resource text may not be a dotted quad. Version version = new Version(versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart); if (EmptyVersion != version) { payloadInfo.Version = version.ToString(); } payloadInfo.ProductName = versionInfo.ProductName; payloadInfo.Description = versionInfo.FileDescription; } }