<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[gOxiA=苏繁=SuFan Blog]]></title> 
<link>https://maytide.net/index.php</link> 
<description><![CDATA[gOxiA,苏繁,sufan,Microsoft MVP]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[gOxiA=苏繁=SuFan Blog]]></copyright>
<item>
<link>https://maytide.net/read.php/2066.htm</link>
<title><![CDATA[HOWTO: 为 MSIX 创建自签名证书]]></title> 
<author>gOxiA &lt;sufan_cn@msn.com&gt;</author>
<category><![CDATA[Deployment]]></category>
<pubDate>Sun, 01 Jan 2023 02:06:00 +0000</pubDate> 
<guid>https://maytide.net/read.php/2066.htm</guid> 
<description>
<![CDATA[ 
	<p><img alt="Windows_logo_horiz_blue_rgb" src="http://goxia.maytide.net/ftpup/2018/Windows-_8577/Windows_logo_horiz_blue_rgb_thumb.png"></p><p><strong><font color="#fd3f0d" size="4">HOWTO: 为 MSIX 创建自签名证书</font></strong></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MSIX 是一种 Windows 应用安装包的格式，它可以将我们的 Win32 或 UWP 甚至是绿色版软件打包成 MSIX 格式用于企业批量和自动化部署。另外从官方文档了解到 1.2019.1220.0 还支持将包含的服务转换为应用程序。这对于一些要部署国产小软件的企业来说是个好消息，未来 <a href="http://goxia.maytide.net" target="_blank">gOxiA</a> 也将尝试去打包那些应用程序。</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 而今天我们要分享的是如何为 MSIX 创建自签名证书，因为 MSIX 生成后要发布给最终用户需要对 MSIX 进行签名，如果当前环境没有 CA 或无法生成所需的证书就需要创建自签名证书，否则无法应用 MSIX。</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在创建自签名证书前，我们需要确定 MSIX 的 发布者信息，通常这些信息位于 AppxManifest.xml 文件中，其 Publisher 信息必须与证书中的主体相同。之后参考下面的命令行创建证书：</p><p><strong><em>New-SelfSignedCertificate -Type Custom -Subject "CN=Contoso Software, O=Contoso Corporation, C=US" -KeyUsage DigitalSignature -FriendlyName "Your friendly name goes here" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37=&#123;text&#125;1.3.6.1.5.5.7.3.3", "2.5.29.19=&#123;text&#125;")</em></strong></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其中：</p><ul><li>-keyusage 表示证书的用途，对于自签名证书，应为 DigitalSignature</li><li>-TextExtension 表示一些扩展设置，2.5.29.37=&#123;text&#125;1.3.6.1.5.5.7.3.3，表示证书用于代码签名；2.5.29.19=&#123;text&#125; 表示该证书非CA</li></ul><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 接下来使用 PowerShell 查看证书信息：</p><p><strong><em>Set-Location Cert:\CurrentUser\My<br/>Get-ChildItem &#124; Format-Table Subject, FriendlyName, Thumbprint</em></strong></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在确认了证书信息后，现在可以将证书导出为 pfx 格式，为此执行：</p><p><strong><em>$password = ConvertTo-SecureString -String &lt;Your Password&gt; -Force -AsPlainText <br/>Export-PfxCertificate -cert "Cert:\CurrentUser\My\&lt;Certificate Thumbprint&gt;" -FilePath &lt;FilePath&gt;.pfx -Password $password</em></strong></p><p><a href="http://goxia.maytide.net/ftpup/2022/HOWTO--MSIX-_F99B/image.png"><img width="634" height="462" title="image" style="margin: 0px; display: inline; background-image: none;" alt="image" src="http://goxia.maytide.net/ftpup/2022/HOWTO--MSIX-_F99B/image_thumb.png" border="0"></a></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 现在我们拿到了 pfx 就可以用于 MSIX 签名，后续 gOxiA 也会积极分享 MSIX 相关的实践。</p><p>参考文档：</p><p><a title="https://learn.microsoft.com/zh-cn/windows/msix/package/create-certificate-package-signing" href="https://learn.microsoft.com/zh-cn/windows/msix/package/create-certificate-package-signing/?WT.mc_id=WDIT-MVP-4000544">https://learn.microsoft.com/zh-cn/windows/msix/package/create-certificate-package-signing</a></p>
]]>
</description>
</item>
</channel>
</rss>