简体   繁体   English

在 SQL 中加密并在 C# 中解密

[英]Encrypt in SQL and Decrypt in C#

We want to encrypt ssn, account number, routing number, etc. Is it possible to encrypt in SQL (using ENCRYPTBYKEY function) and decrypt in C# or vice-versa?我们要加密ssn,帐号,路由号码等。是否可以在SQL中加密(使用ENCRYPTBYKEY函数)并在C#中解密,反之亦然? We could encrypt and decrypt using SQL itself but we're using a lot of LINQ queries in our code which we would need to move to SQL.我们可以使用 SQL 本身进行加密和解密,但是我们在代码中使用了大量 LINQ 查询,我们需要将这些查询转移到 SQL。 Also, if we encrypt/decrypt in C#, we would not be able to use the encrypted columns in our stored procs and SSRS reports.此外,如果我们在 C# 中加密/解密,我们将无法在存储的 procs 和 SSRS 报告中使用加密列。 Please advice the best way to achieve this.请建议实现这一目标的最佳方法。 Thanks.谢谢。

I will give different answer:我会给出不同的答案:

Best practice is, not having decrypt function at all.最佳做法是,根本没有解密功能。 When user enters data, encrypt/encode them and save them into database.当用户输入数据时,对它们进行加密/编码并将它们保存到数据库中。 next time, whenever there is need to match users' data, compare encrypted content and allow them to do further operations only if they match.下次当需要匹配用户的数据时,将加密的内容进行比较,匹配到才允许他们做进一步的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM