-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption.sql
More file actions
30 lines (22 loc) · 1.17 KB
/
Encryption.sql
File metadata and controls
30 lines (22 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--==--------------------------------------------------------------------------------------------------------------
--To encrypt credit card number table
-- Add an encrypted column to store the credit card number
ALTER TABLE Payment.Payments
ADD EncryptedCreditCard VARBINARY(MAX);
-- Update existing records with encrypted credit card numbers
UPDATE Payment.Payments
SET EncryptedCreditCard = ENCRYPTBYPASSPHRASE('Agent001hubkad', CreditCardNumber);
-- Remove the original credit card number column
ALTER TABLE Payment.Payments
DROP COLUMN CreditCardNumber;
--==--------------------------------------------------------------------------------------------------------------
--To decrypt credit card number table
-- Add a new column to store the decrypted credit card number
ALTER TABLE Payment.Payments
ADD DecryptedCreditCard VARCHAR(30);
-- Update existing records with decrypted credit card numbers
UPDATE Payment.Payments
SET DecryptedCreditCard = CONVERT(VARCHAR(30), DECRYPTBYPASSPHRASE('YourSecretPassphrase', EncryptedCreditCard));
-- Drop the encrypted column as it's no longer needed
ALTER TABLE Payment.Payments
DROP COLUMN EncryptedCreditCard;