簡體   English   中英

如何使用sqlserver.management.smo通過symmetryk密鑰從sql server中的表中獲取加密記錄

[英]How to get encrypted records from table in sql server by symmetryk key using sqlserver.management.smo

我在密碼字段中使用了SymmetricKey。 現在我想使用解密的密碼從該表中獲取所有記錄。 我正在使用Microsoft.SqlServer.Management.Smo。

var tbls = new Table();
tbls = db.Tables[tblname];
ScriptingOptions options = new ScriptingOptions();
options.ScriptData = true;
options.ScriptDrops = false;
options.EnforceScriptingOptions = true;
options.ScriptSchema = false;
options.IncludeHeaders = true;
options.AppendToFile = true;
options.Indexes = true;
options.WithDependencies = true;                                
ServerVersion sv = new ServerVersion(2008, 2005);
options.SetTargetServerVersion(sv);
var script = tbls.EnumScript(options);
string queryes ="";                                 
foreach (var line in script)
{
   if (line.Contains("VALUES"))
   {
      queryes += line;                                        
   }
}

如何獲取解密記錄的數據?

如果該字段已經使用對稱密鑰加密,則應使用以下語句使用對稱密鑰將其打開。

OPEN SYMMETRIC KEY [Key Name] Decryption by [Decryption Mechanism]

以下鏈接可以幫助您了解對稱密鑰,非對稱密鑰以及創建用於加密和解密數據的證書。 [ https://msdn.microsoft.com/en-us/library/ms190499.aspx]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM