473,480 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

RC4 Encryption with Access/VBA

BHo15
143 New Member
This is a question for all, but Rabbit... I read your article on RC4 ("RC4 Encryption Algorithm for VBA and VBScript"), and have used it in a DB. It works great, but of course all I am doing is obfuscating the data instead of actually encrypting (because the key is kept in the database).

Do you know of a way to hide the key when using RC4 in a typical Access DB?

Thanks,
Brad
Jul 18 '14 #1
20 2781
Rabbit
12,516 Recognized Expert Moderator MVP
You use a password entry form to let the users that have access to that particular data enter the password.

If your goal is to allow anyone who has legitimate access to the database see all the data, then you don't really need to use the encryption functions in my articles. You can just use the built in full file encryption that comes with Access. It's quicker and encrypts everything instead of just the data.

Where my encryption code would come in is when you want some users to have access to some of the data. In this scenario, you encrypt the confidential data with a password only they know and you use a form to let them enter the password for encryption / decryption. The form would compare the password hash to the hash of their entry to make sure they entered the correct password without storing the actual password.
Jul 18 '14 #2
BHo15
143 New Member
Actually, what I am using the RC4 for is to encrypt the table containing user passwords to enter the database. The RC4 function is used encrypt the password they choose, and then used to decrypt it to check it against what the PW they enter upon opening the DB.

So the encryption is working great, but the RC4 function requires a key, and I just can't figure out a way to hide the key being used (key management).

Thanks.
Jul 18 '14 #3
Rabbit
12,516 Recognized Expert Moderator MVP
You don't encrypt passwords for storage. Instead, you hash the passwords and store the hash. Hashes don't require a password to use and are one way only, meaning you can't take the hash and retrieve the original value. Which is fine for passwords because you don't need the original password, you only need to compare if two hashes are the same.
Jul 18 '14 #4
NeoPa
32,556 Recognized Expert Moderator MVP
While that may take a bit of getting one's head around, it is solid advice. Few understand security as well as Rabbit.

From the few posts you've added it seems clear you're reasonably bright and capable. I expect you'll understand what Rabbit's saying better than most. Feel free to question further if required but I suspect you have all you need. Let us know how you get on.
Jul 18 '14 #5
BHo15
143 New Member
The hash makes all the sense in the world. Believe it or not... I've got a CISSP, but am just beginning to learn how every thing fits together in the real world. :)

What data type should I be using in the table to store the hash? I tried Long Text, and got a Type Mismatch when trying to run my update command.
Jul 18 '14 #6
Rabbit
12,516 Recognized Expert Moderator MVP
The hash result comes as an array of integers. It's up to you how you want to store that. Some people convert the array into an ASCII string while others convert it to a string of hex values.
Jul 20 '14 #7
BHo15
143 New Member
Arrays have always been my weak spot (unfortunate, isn't it?). I would assume that I would need to parse out the array values by the commas?, and then use a function to convert it all to an ASCII string?

I would like to know how to do this, but I did find another solution. It appears to do what I want it to, and also appears to be fairly secure. Here is the code for resetting a password...

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtPW_AfterUpdate()
  2.     DoCmd.SetWarnings False
  3.     DoCmd.RunSQL "UPDATE tblPWs SET tblPWs.PW = '" & Hash(Forms!frmTest.txtPW) & "'"
  4.     DoCmd.SetWarnings True
  5. End Sub
Jul 22 '14 #8
BHo15
143 New Member
Sorry... Left out the module for the Hash. Here it is.

Expand|Select|Wrap|Line Numbers
  1. 'From http://www.freevbcode.com/ShowCode.asp?ID=972
  2.  
  3. Public Function Hash(ByVal text As String) As String
  4.     a = 1
  5.     For i = 1 To Len(text)
  6.         a = Sqr(a * i * Asc(Mid(text, i, 1))) 'Numeric Hash
  7.     Next i
  8.     Rnd (-1)
  9.     Randomize a 'seed PRNG
  10.     For i = 1 To 16
  11.         Hash = Hash & Chr(Int(Rnd * 256))
  12.     Next i
  13. End Function
Jul 22 '14 #9
Rabbit
12,516 Recognized Expert Moderator MVP
There are no commas in an array, it's distinct elements. You loop through each element and concatenate the values into one string.

I would be careful with that hashing algorithm you found. It's unlikely to be considered a cryptographically secure algorithm. Meaning it's likely to have weaknesses that can be exploited to find the original values.
Jul 22 '14 #10
BHo15
143 New Member
So, I'm getting a little closer. If I loop through the array to get all of the values and put them into a string (such as below)...
Expand|Select|Wrap|Line Numbers
  1.     For x = LBound(arrHash) To UBound(arrHash)
  2.         strArr = strArr + CStr(arrHash(x))
  3.     Next x
... I would begin with an array such as this - 231, 207, 62, 244, 241, 124, 57, 153, 169, 79, 44, 111, 97, 46, 138, 136, 142, 91, 16, 38, 135, 142, 78, 25, 57, 139, 35, 189, 56, 236, 34, 26, and end up with a string such as this - 23120762244241124571531697944111974613813614291163 813514278255713935189562363426.

What am I missing?

Thanks for the patience.
Brad
Jul 22 '14 #11
Rabbit
12,516 Recognized Expert Moderator MVP
That depends on if you want to store it as a hex string to make it more human readable or a regular string. The easiest would be to store it as a regular string in which case you use the CHR() function to convert the integer to a character before you append it to the string.
Jul 22 '14 #12
BHo15
143 New Member
BEAUTIFUL!!!

That's what I needed. That gets me a nice obscure string to append to the table.

Thanks ever so much for the help (and even for making me dig a bit... you know - it helps with the learning :)
Jul 22 '14 #13
Rabbit
12,516 Recognized Expert Moderator MVP
No problem, good luck with the rest of your project.

I'm glad you like my style of guidance. I prefer to give small hints in the hopes that working through the problem will provide more knowledge in the long run.

Here are a couple of other things you can do to improve the security of your username/password table.

1) Hash the username. Because Access doesn't have a way to prevent users from accessing the table, a user can potentially mess with the table if they know which row belongs to which user.

2) Incorporate a salt into the hash. Because some people can use the same password as another user, the hash will come out the same. To prevent the same hash for the same password, it is recommended that you supply a "salt" or "initialization vector" to the hash. Basically, what you are doing here is supplying a known value that is used to modify the pre-hash string before hashing, this results in a different hash even if you are hashing the same value. One common way of doing this is using a unique id to xor each byte of the pre-hash value.
Jul 22 '14 #14
BHo15
143 New Member
Salting is a good idea. I understand what it is, but don't know how to use it. If I salt, how do I make sure that I get the same thing every time the user enters the DB? I saw something on the web about storing the salt and the hashes separately, but that doesn't make any sense to me.

Thoughts?
Jul 22 '14 #15
BHo15
143 New Member
In doing more reading, I see several examples of tables containing [1] Username, [2] Password Hash, and [3] Password Salt. If you store them all together, what stops an attacker from taking the salt and adding it to the beginning (or end) of the passwords used in a rainbow attack?
Jul 23 '14 #16
Rabbit
12,516 Recognized Expert Moderator MVP
It doesn't. It's just an extra layer for them to deal with. The salt merely prevents a hacker from using an existing rainbow table to easily crack the passwords. Instead of doing a simple hash lookup, they now have to recalculate the entire rainbow table for every password. The hope is that the increased amount of time to do so would deter them from attempting it. But someone who really wanted to crack the passwords will be able to, it will just take them a lot longer than it would without the salt. It's one of the reasons why it is recommended practice to change passwords every few months.

All passwords will be cracked with enough time. How long you have depends on the randomness of the password, the length of the password, and how that password is stored (in plain text, hashed, salted and hashed, encrypted, salted and encrypted).
Jul 23 '14 #17
BHo15
143 New Member
Got it. So what is best practice for the length of Salt?
Jul 23 '14 #18
Rabbit
12,516 Recognized Expert Moderator MVP
I don't know that there is a best practice. A cryptographically secure hashing algorithm should result in a completely different hash even if one byte of data is changed. So the length isn't much of an issue. The only lower limit on length is that it needs to be big enough to give a distinct value for every password you want to hash.
Jul 23 '14 #19
BHo15
143 New Member
If that's the case... I'm in good shape.

Thanks for all the help Rabbit.
Jul 23 '14 #20
Rabbit
12,516 Recognized Expert Moderator MVP
No problem, good luck on the rest of your project.
Jul 23 '14 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7118
by: Cliff | last post by:
We are trying to connect to 3 different Oracle databases using MS Access as the front-end and ODBC as the connection. The problem that we are having is that 1 of the databases requires a...
2
2115
by: gaurav khanna | last post by:
Hi I need to store the credit card information in my database. I have been looking for some third party tools which could provide encryption for credit card numbers. The help I need is: a)...
2
1577
by: Juan Luis Medina | last post by:
Hello all, I want to use MS Access 2000 to authenticate users in a program. So I will build a table with the fields usernames and passwords at least and then I want to use this information from...
3
3064
by: Mike Wilson | last post by:
Is there a way to open an OLE DB database from within Access? I would like to use the Access GUI with its table and query explorer to examine a database only available through an OLEDB provider...
27
3067
by: MLH | last post by:
Silly me. I thought that if I clicked Tools, Security, Encrypt database MyDB.mdb to Ncrypt.mdb I would not be able to read the module code if opening Ncrypt.mdb inside A97 later. I've found that...
113
12173
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
17
2454
by: DaveG | last post by:
Hi all I am planning on writing a stock and accounts program for the family business, I understand this is likely to take close to 2 years to accomplish. The stock is likely to run into over a...
7
6109
by: Steven Cliff | last post by:
I have started to use the new Enterprise Library (Jan 06) and have set up a skeleton project using the DAAB. This all seems to work fine apart from when I come to secure the app.config file via...
10
409
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Thank you for that. It was very...
1
9029
Rabbit
by: Rabbit | last post by:
INTRODUCTION There has been considerable interest in the forum regarding Access and security. This is a primer on that topic. First off, if you have a need for security, don't do it in Access....
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.