当您告诉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
或Base64编码用AQAAANCMnd8BFdERjHoAwE/Cl+
,这里。
对于用C#解密,可以使用类,ProtectedData
或更确切地说,ProtectedData.Unprotect
可以使用静态方法。如果熵的值未知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的Python中win32crypt.CryptUnprotectData
或带Java DPAPI的Java中),其他语言也可以实现解密。
这是一个控制台程序,可获取解码数据的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));
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句