点击一次 - 如何加密连接字符串 [英] Click-Once - How to encrypt connection strings

查看:160
本文介绍了点击一次 - 如何加密连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,连接字符串存储在App.config中。在单次点击部署中加密这些连接字符串的最佳方式是什么?



谢谢

解决方案

如果这是一个将配置的connectionString并且通过应用程序的实例在单个计算机(不共享多台计算机)上使用,您可以使用DPAPI(Data Protection API)的.NET托管包装器 - ProtectedData类(System.Security.Cryptography)。



你还可以使用一个整洁的技巧(你应该决定使用这个类)是为字符串编码和解码创建扩展方法,所以操作变得简单:

  string encodedString = myConnectionString.EncodeString(); 

string decodedString = encodedString.DecodeString();

希望这有帮助!


I have a WPF application with connections strings stored in the App.config. What is the best way of encrypting these connection strings in a click-once deployment?

Thanks

解决方案

If this is a connectionString that will be configured and used on a single computer (not shared across multiple computers) by an instance of your application, you can use the .NET managed wrapper of the DPAPI (Data Protection API) - the ProtectedData class (System.Security.Cryptography).

A neat trick you could also use (should you decide to use this class) is to create extension methods for Encoding and Decoding a string, so the operations become as simple as:

string encodedString = myConnectionString.EncodeString();

string decodedString = encodedString.DecodeString();

Hope this helps!

这篇关于点击一次 - 如何加密连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆