Encripting SSN

P

Pat Hartman

I am using an SQL 2005 be and I need to encrypt the SSN field. Does anyone
have VBA code examples? How do you protect the key so that it doesn't die
with the developer?
 
A

Arvin Meyer [MVP]

Pat Hartman said:
I am using an SQL 2005 be and I need to encrypt the SSN field. Does anyone
have VBA code examples? How do you protect the key so that it doesn't die
with the developer?

I'm not very keen on storing SSN's in any database not required by law, so
do say you weren't warned. You'll need to protect this code with an MDE and
use the same routine to decrypt. The password, must be supplied each time,
if you want it to be secure. If it's not, merely copying and pasting back
will cough up the correct answer. As far as protecting it, make a copy and
put it in the safe. Run an query to dycrypt and re-encrypt with each change
of personnel. Obviously, the longer and more complex the password key is,
the better it will protect:

Public Function Encrypt(ByVal strIn As String, ByVal strKey As String) As
String
On Error GoTo Error_Handler

Dim i As Integer
Dim bytData As Byte
Dim bytKey As Byte
Dim strEncrypted As String

Encrypt = vbNullString

For i = 1 To Len(strIn)
bytData = Asc(Mid(strIn, i, 1))
bytKey = Asc(Mid(strKey, (i Mod Len(strKey)) + 1))
strEncrypted = strEncrypted & Chr(bytData Xor bytKey)
Next i

If strEncrypted <> vbNullString Then
Encrypt = strEncrypted
End If

Exit_Here:
Exit Function

Error_Handler:
Resume Exit_Here
End Function
 
P

Pat Hartman

Thanks Arvin, you've been very helpful today. I hate keeping SSNs also but
the client is using a third party service to obtain information on broker
license information and they need SSN's for individuals and FEINs for
agencies in order to obtain the necessary license information. So we're
stuck since the company is growing so fast it has become a burden keeping up
with licensing for hundreds of brokers and doing business with an unlicensed
broker or agency runs the risk of fines and other sanctions so it is pretty
important to them.
Happy New Year!
 
P

Pat Hartman

OOPS, Your encryption routine doesn't include the algorithm for decrypting
the string. Do you have one?
 
T

Tony Toews [MVP]

Pat Hartman said:
I am using an SQL 2005 be and I need to encrypt the SSN field. Does anyone
have VBA code examples? How do you protect the key so that it doesn't die
with the developer?

I've been using the Microsoft Crypto API. However I can't recall the
exact URL now.

Tony

--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Top