我能够使用以下代码在 SQL 中进行列加密:
USE EncryptionDemonstration
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'ThisIsMySampleStrongPassword'
CREATE CERTIFICATE MyServerCertificate WITH SUBJECT = 'This is my Demonstration Certificate'
CREATE SYMMETRIC KEY SSN_Keys
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE MyServerCertificate;
GO
CREATE SYMMETRIC KEY CreditCard_Keys
WITH ALGORITHM = AES_128
ENCRYPTION BY CERTIFICATE MyServerCertificate;
ALTER TABLE Customer
ADD SSN_Encrypted varbinary(128),
CCN_Encrypted varbinary(128)
OPEN SYMMETRIC KEY CreditCard_Keys
DECRYPTION BY CERTIFICATE MyServerCertificate
OPEN SYMMETRIC KEY SSN_Keys
DECRYPTION BY CERTIFICATE MyServerCertificate
UPDATE Customer
SET SSN_Encrypted = EncryptByKey(Key_GUID('SSN_Keys')
, …Run Code Online (Sandbox Code Playgroud)