代码之家  ›  专栏  ›  技术社区  ›  Dominic Zukiewicz

如何在SQLServer2005中对现有列使用安全加密

  •  1
  • Dominic Zukiewicz  · 技术社区  · 15 年前

    我想使用UPDATE语句加密SQLServer2005中的现有列,将旧内容移动到新的加密列中。

    所以我有两个选择:对称和不对称。

    -- Create key (at some earlier point)
    create symmetric key sk_user_profile with algorithm = aes_192 encryption by password = 'P@ssword!!';
    
    -- Now encrypt the contents
    -- open the key so that we can use it
    open symmetric key sk_user_profile decryption by password = 'P@ssword!!';
    
    UPDATE users
    SET password_enc = encryptbykey(key_guid('sk_user_profile'), password_plain, 1, user_id)
    
    close symmetric key sk_user_profile
    

    现在如果我想选择数据,我仍然需要用

    open symmetric key sk_user_profile decryption by password = 'P@ssword!!';
    

    一些问题

    1. 有没有办法解决这个问题-即用这个密码创建一个证书,然后改为引用证书?
    2. 此方法是否可跨故障转移群集数据库进行扩展,即加密不基于计算机,仅基于提供的密码。因此,故障转移仍然可以读取密码

    谢谢你的帮助

    1 回复  |  直到 15 年前
        1
  •  1
  •   Denis Valeev    15 年前

    基本上你需要做的是:

    create certificate MyEncryptionCertificate with subject = 'MyCertificate'
    
    create symmetric key MySymmetricKey with algorithm = aes_256 encryption by certificate MyEncryptionCertificate
    

    然后:

    open symmetric key MySymmetricKey decryption by certificate MyEncryptionCertificate
    
    select encryptbykey(key_guid('MySymmetricKey'), 'tada')) EncryptedMessage
    

    我希望这个博客能对你有所帮助。

    SQL SERVER – Introduction to SQL Server Encryption and Symmetric Key Encryption Tutorial with Script

    还有这个博客,它专门处理故障转移环境中的证书。

    Solution Using Certificates Authentication on Production Servers