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

您所在的位置:网站首页 encryptedpassword Visual Studio 如何加密 .pubxml.user 文件中的密码?答案

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

#Visual Studio 如何加密 .pubxml.user 文件中的密码?答案| 来源: 网络整理| 查看: 265

数据经过DPAPI 加密。 DPAPI 加密数据以十六进制开头,字节序列为0x01000000D08C9DDF0115D1118C7A00C04FC297EB,或者Base64 编码为AQAAANCMnd8BFdERjHoAwE/Cl+、here。

对于 C# 解密,可以使用类 ProtectedData 或更准确地说是静态方法 ProtectedData.Unprotect。如果熵s_aditionalEntropy 的值未知,则应尝试null。有关此参数的更多信息,请参阅here。

如果加密后的数据是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 中使用 win32crypt.CryptUnprotectData 或在 Java 中使用 Java DPAPI。

这是一个获取解码数据的 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)); } } }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3