Visual Studio如何加密.pubxml.user文件中的密码?

耶兹

当您告诉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_aditionalEntropynull则应尝试。有关此参数的更多信息,请参见此处

如果加密的数据是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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在发布配置文件(.pubxml)中配置“ appOfflineTemplate”?

对于 DevOps Release,如何配置 pubxml 和密码以部署到 Azure 应用服务?

如何在没有密码的情况下在版本控制中签入Azure .pubxml?

.pubxml中无法识别<_CustomFiles>元素

intellisense无法识别PUBXML中的正确标签

在Visual Studio 2017中加密连接字符串

如何加密密码-Android Studio

如何从 Visual Studio 中删除 Excel 文件?

使用C#中的文本文件替换pubxml中的参数

如何在 Kotlin/Android Studio 中删除加密文件

如何在C ++中的Visual Studio 2010中添加.a文件

密码如何加密到密钥表文件中?

如何在zip bat文件中添加密码命令

在TFS上发布找不到Node.js测试项目的pubxml文件

如何在Visual Studio 2013中打开SSRS(.rptproj)文件?

如何在 Visual Studio 中双击打开文件?

如何在Visual Studio中编译C ++文件?

如何在Visual Studio 2013中添加新的C文件

如何在Visual Studio中搜索文件名?

如何在Visual Studio中更改单个文件的语法

如何在Visual Studio中实际搜索所有文件

如何在Visual Studio代码中调试打字稿文件

如何在Visual Studio中添加资源文件

如何在Visual Studio中安装VSIX文件?

如何在 Visual Studio 代码中合并文件(区分)

如何在Visual Studio 2012中快速打开文件

如何从Visual Studio中的Xunit测试引用测试文件?

如何转到Visual Studio中的最后一个文件?

如何自动使用Visual Studio的“在文件中查找”功能?