Visual studio Visual Studio如何加密.pubxml.user文件中的密码?
当您告诉Visual Studio为发布配置文件保存密码时,它会在发布文件旁边创建一个Visual studio Visual Studio如何加密.pubxml.user文件中的密码?,visual-studio,encryption,passwords,visual-studio-2019,webdeploy,Visual Studio,Encryption,Passwords,Visual Studio 2019,Webdeploy,当您告诉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
.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>
AQAAANC[…]
Visual Studio如何在EncryptedPassword
元素中加密密码?我想解密它,因为我忘记了我的密码。。。现在它只是加密存储在这个文件中 数据是加密的。DPAPI加密数据以十六进制开头,字节序列为0x01000000D08C9DDF0115D1118C7A00C004FC297EB或Base64,编码方式为AQAAANCMnd8BFdERjHoAwE/Cl+
对于C#类的解密,或者更准确地说,可以使用静态方法。如果熵s_aditionalEntropy
的值未知,则应尝试null
。可以找到有关此参数的更多信息
如果加密数据是Base64编码的,则在解密之前必须对其进行Base64解码:
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);
链接文档中提供了更详细的示例。解密不仅限于.NET,还可以使用其他语言,只要存在相应的DPAPI包装器,例如在Python with或Java with中
下面是一个控制台程序,用于获取解码数据的Unicode字符串表示形式:
using System;
using System.Security.Cryptography;
namespace ConsolePassDecrypter {
class Program {
static void Main(string[] args) {
string encryptedPass = "AQAAANC[...]";
var decryptedPassBytes = ProtectedData.Unprotect(Convert.FromBase64String(encryptedPass), null, DataProtectionScope.LocalMachine);
Console.WriteLine("Decrypted pass: " + System.Text.Encoding.Unicode.GetString(decryptedPassBytes));
}
}
}
基于开头
AQAAANC
的纯猜测:开头是AQAAANCMnd8BFdERjHoAwE/Cl+
(它是0x01000000d08c9ddf01115d118c7a00c04fc297eb
的Base64编码)吗?然后它们可能被DPAPI加密。在对数据进行Base64解码之后,应该可以使用C#类进行解密,更准确地说是使用方法ProtectedData.Unprotect
(有关示例,请参阅链接文档)。如果s_aditionalEntropy
没有已知值,我会尝试null
@Topaco请给出答案,我可以奖励奖金。