[当您告诉Visual Studio保存发布配置文件的密码时,它将在发布文件旁边创建一个.pubxml.user
文件,看起来类似于以下内容:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TimeStampOfAssociatedLegacyPublishXmlFile />
<EncryptedPassword>AQAAANC[...]</EncryptedPassword>
</PropertyGroup>
</Project>
[Visual Studio实际上如何加密EncryptedPassword
元素中的密码?我想解密它,因为我忘记了密码...现在它已加密存储在此文件中!
[数据已加密DPAPI。 DPAPI加密的数据以字节序列0x01000000D08C9DDF0115D1118C7A00C04FC297EB
或以AQAAANCMnd8BFdERjHoAwE/Cl+
,here编码的Base64以十六进制开头。
对于使用C#进行解密,可以使用类ProtectedData
,或更确切地说,可以使用静态方法ProtectedData
。如果熵ProtectedData.Unprotect
的值未知,则应尝试ProtectedData.Unprotect
。有关此参数的更多信息,请参见s_aditionalEntropy
。
如果加密的数据是Base64编码的,则在解密之前必须对它们进行Base64解码:
null
更详细的示例可以在链接的文档中找到。解密不限于.NET,其他语言也可以进行解密,前提是存在相应的DPAPI包装器,例如在Python中使用here或在Java中使用using System.Security.Cryptography;
...
String encryptedDataB64 = "AQAAANCMnd8BFdERjHoAwE/Cl+...";
byte[] encryptedData = Convert.FromBase64String(encryptedDataB64);
byte[] s_aditionalEntropy = null;
byte[] data = ProtectedData.Unprotect(encryptedData, s_aditionalEntropy, DataProtectionScope.CurrentUser);
。
这是一个控制台程序,它获取解码数据的Unicode字符串表示形式:
win32crypt.CryptUnprotectData
Visual Studio将按用户/每台计算机加密密码值。因此,如果将同一文件带到另一台计算机上(或者,如果其他用户登录到同一台计算机),它将无法解密为正确的值。因此,您需要重设密码,而不是解密密码。