英文:
Entity Framework Core and column level SQL Server encryption with stored procedures, how to map properties the right way?
问题
我已经使用Entity Framework Core编写了SQL Server加密/解密的存储过程和对称密钥的工作。
我可以将对象保存到数据库中,我将SSNumber
参数传递给存储过程,它会加密并存储在SSNumberEncrypted
中。
我还编写了一个用于获取记录的存储过程,我设置属性SSNumber = DecryptByKey(SSNumberEncrypted)
。如果我在SSMS中运行它,它可以正常工作并获取到SSNumber
,但是当我从C#中执行存储过程时,属性值始终为null,因为有NotMapped
属性。
是否有一种方法可以实现这个目标?
public class Test
{
public long Id { get; set; }
[NotMapped]
public string SSNumber { get; set; }
public byte[] SSNumberEncrypted { get; set; }
}
英文:
I have made work SQL Server encryption/decryption using stored procedures, symmetric keys using Entity Framework Core.
I am able to save the object in the database, I pass the SSNumber
parameter to the stored procedure, it encrypts it and stores it in SSNumberEncrypted
.
I also coded a stored procedure to get the record, I set the property SSNumber = DecryptByKey(SSNumberEncrypted)
. If I run it in SSMS, it works and I get the SSNumber
, but when I execute the stored procedure from C#, the property value is always null, because of the NotMapped
attribute.
Is there a way that I can accomplish this?
public class Test
{
public long Id { get; set; }
[NotMapped]
public string SSNumber { get; set; }
public byte[] SSNumberEncrypted { get; set; }
}
答案1
得分: 2
以下是翻译好的内容:
你可以尝试这样做:
public class Test
{
public long Id { get; set; }
[NotMapped]
public string SSNumber { get=>DecryptByKey(SSNumberEncrypted);
set=>.......; }
public byte[] SSNumberEncrypted { get; set; }
}
英文:
You may try this:
public class Test
{
public long Id { get; set; }
[NotMapped]
public string SSNumber { get=>DecryptByKey(SSNumberEncrypted);
set=>.......; }
public byte[] SSNumberEncrypted { get; set; }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论