解密问题

时间:2009-07-16 10:41:33

标签: sql sql-server sql-server-2005 certificate ssl-certificate

我使用加密在表中插入了一些数据(通过创建我自己的证书加密)。

INSERT
INTO Person2(ContactID, eFirstName, eMiddleName, eLastName)
Values (1, EncryptByCert(Cert_ID('TestCertificate'), 'FirstName'),
   EncryptByCert(Cert_ID('TestCertificate'), 'Middle Name'), 
   EncryptByCert(Cert_ID('TestCertificate'), 'Last Name'))

然后像这样更新表格的其他列

UPDATE Person2
SET FirstName = DecryptByCert(Cert_ID('TestCertificate'), eFirstName),
MiddleName = DecryptByCert(Cert_ID('TestCertificate'), eMiddleName),
LastName = DecryptByCert(Cert_ID('TestCertificate'), eLastName);

最终结果是这样的

1   楆獲乴浡e   楍摤敬丠浡e  慌瑳丠浡e   0x42712BB8DE86BE3E7BDAADF973476730D345EE5B4B3A3CFA2BDAF7128FEF6E85928AB69C8C866DFD66F65F0E8588C8463AE00984A81E8AAB712C1120DA20DD31BCB13C39971D4E48711AAF87A665F1B0809A06E69057861E828C4F82B7F6745722CE32C63F826FB3ECC26F59C525C2D6DE5D4B974B05F557963440E153A9483D  0x94003DE781AC56AC691DC883E2E3AB78975E36CEB378F7FD1F7844102DA07D6233F9B8D022C38A629960D7D5C7FEA6603B955F2DF82317B826F4472D5638F26EBFE46488BE35445144776CC4697A5852E0C6F68E302CEF0C9D32DFD4495E16EC80FF730F571A9499E463443E24FB66ED10BD57E6AC3D628038C859B4C8EEC049  0x2A9041F6BEBE9A42B76D7A1817A351073A59DD852D4C067614E5B6773BD0FCEC44A8E94E87B2F0B2D3AC7F8E5D8A831B159A675C81AED07AA4F9982FBF5689C713D80BA97DE19FA116A507268C0098AEB5F56C95FF83B2F2448ED6EB387444CF53A2666B34E0478BD4337CCFF5C007D960D96FEEF6FD77C8300805593569E352

第一个像中文语言风格的树状结构应该包含值'FirstName' 'MiddleName' and 'LastName' 任何一个帮助是什么问题?

1 个答案:

答案 0 :(得分:1)

试试这个:

INSERT
INTO Person2(ContactID, eFirstName, eMiddleName, eLastName)
Values (1, EncryptByCert(Cert_ID('TestCertificate'), N'FirstName'),
    EncryptByCert(Cert_ID('TestCertificate'), N'Middle Name'),
    EncryptByCert(Cert_ID('TestCertificate'), N'Last Name'))

我认为问题可能是你正在加密ANSI字符串(varchar)但是解密为unicode(nvarchar)。