Populate the Hash Columns
The next step will be to populate our new Identification_Value_H and Identification_Value_HT columns with the hash values of the Identification_Value column.
Listing 4 shows the script to do this. It uses the GetHashSalt user defined function to salt the values in the Identification_Value column and then updates the data in our the newly-created hash columns in our Borrower_Identification table so that they are salted and hashed, in the case of the Identification_Value_H column, and salted, truncated and hashed, in the case of the Identification_Value_HT column.
Verify the Implementation
To verify that our hash values were successfully generated, we can execute SELECT statements that filter, based upon our newly generated columns, as shown in Listing 5.
The results of these queries, indicating successful implementation of one-way encryption, would appear as follows:
Identification_Value
-------------------------------------------------------
555-20-7151
(1 row(s) affected)
Identification_Value
-------------------------------------------------------
555-20-7151
(1 row(s) affected)
Drop the Unencrypted Column
Having successfully encrypted the contents of our Identification_Value column, captured it into the Identification_Value_H and Identification_Value_HT columns, and verified that they are working correctly; we can remove the Identification_Value column that contains the plain text values of our sensitive data.
This is accomplished through the use of the ALTERTABLE method and the DROP COLUMN argument, as shown in Listing 6.
Please note that the plain text values contained in
this column will be permanently lost with its removal. This is
definitely an action in which we will want to take pause. Perform the DROPCOLUMN
command only if you are certain that you will no longer need to
reference its contents. At the beginning of this process we performed a
database backup which will provide us a means of recovery if needed. If
the plain text values are archived to another location it too will need
to be protected.