encrypt data

N

nerea

I need to encrypt some fields in the database.
How can I do it?
I was thinking about encrypting the data in vba code and
insert it in the table each time it's modified.
Sb know which are the instructions to do it?
Thanks

Nerea
 
D

Dan Artuso

Hi,
Here is a simple encrypt/decrypt routine. The 'key' is 5656 but you can change that to anything
you like:

Public Function Decrypt(strIn As String) As String
Dim strChr As String
Dim i As Integer
Dim j As Integer

j = 1

For i = 1 To Len(strIn) / 4
strChr = strChr & Chr(CLng(Mid(strIn, j, 4)) Xor 5656)
j = j + 4
Next i
Decrypt = strChr
End Function

Public Function Encrypt(strIn As String) As String
Dim strChr As String
Dim i As Integer

For i = 1 To Len(strIn)
strChr = strChr & CStr(Asc(Mid(strIn, i, 1)) Xor 5656)
Next i
Encrypt = strChr
End Function
 
T

TC

Ouch! I feel a known plaintext attack coming on ...

If anyone knows a single example of original text, & the corresponding
encrypted text, they can immediately decrypt every other encrypted text. I
feel that we should point this out, when recommending XOR methods. What if
these posters are planning on encrypting credid card numbers (or somesuch)?

Cheers,
TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top