views:

101

answers:

7

What algorithm should I use for encrypting and embedding a password for an application?

It obviously is not bullet proof, but it should be good enough to thwart someone scanning the database with a hex editor, or make it hard for someone who has the skills to use a debugger to trace the code to work out, either by scanning for the encrypted password, or using a debugger to run through the decryption code.

Object Pascal would be nice.

Major Edit

I think I did not explain myself well enough. The password needs to be decrypted back into its original form and applied. The application itself uses a local SQL database and a local webserver, and the password is fixed and can't be changed by the end users. It is to ensure that changes to be made only from within the app itself. The user passwords are only to allow access to the app itself, rather than the database

/vfclists

+1  A: 

If you want an easy solution just stick with a good hashing algorithm like MD5 and store just the hash inside your application. Then whenever the user inserts the password you will calculate the hash of the password and check if it's equal to the one stored.

Of course this approach is a simple solution that doesn't allow you to retrieve the password if it's lost but it should work quite fine if you just need some protection..

EDIT: I mentioned MD5 that was fair good but not anymore, of course you can choose any other stronger function like SHA-2 (512/384) that is more robust. I just wanted to explain an approach more than using a specific hashing algorithm.

Jack
MD5 is not a good hashing algorithm any more - Xiaoyun Wang's attacks in 2005 have left it pretty well discredited.
David M
So +1 for the hashing answer, -1 for the MD5 recommendation...
David M
@David M, md5 is not going to be the weak link in this scenario...
Will
Yes, very true. Missed that lack of salting in this answer...
David M
Everything depends on what kind of security you want to prove. Of course having a salt is __necessary__ when we're talking about accounts of a website. But for a casual application that only needs to store the password is an encrypted way this will just move the problem in where to store the salt separately to effectively have some benefits. :)
Jack
A: 

SHA should be ok for you, best with salt.

I don't know Object Pascal very well, but probably this will help you: http://sourceforge.net/projects/op-crypt/

Masala
A: 

When an application has to do password checking only, it is best to save a hash. An hash can not be decrypted, but it can be checked whether the password the user enters has the same hash.

If you want to save the password so that it can be recovered, it is best to encrypt it first, using some crypto library.

Sjoerd
+1  A: 

go through the details here http://www.jasypt.org/howtoencryptuserpasswords.html

Pangea
A: 

I would suggest SHA1, its one way encryption, i've used it before and by far no one has decrypted it! If you need more information on sha1 visit http://en.wikipedia.org/wiki/Secure_Hash_Algorithm and http://www.openssl.org/docs/crypto/sha.html.

PS: If you're using php you can simply encrypt with SHA1 using the sha1(); function!

Daniel
A: 

I suspect that what you're aiming for is not storing passwords in the application, but trying to prevent the application itself from being run without the password, as a form of DRM. If that's the case, and you're looking to stymie people with debuggers, I think you're well into the realm of needing either a hardware dongle, or a network-based lock. Off the top of my head, I know SafeNet carry products that do this (and I've had some exposure to them in the past, they seem decent), but I don't know how well they compare to the rest of the market.

regularfry
A: 

If you want as much real security as is possible in the scenario you're describing, you should require that when the system is installed an "administrator" enters the database password and his own administrator password; the application should then store a salted hash of the administrator's password, and it should store the database password encrypted with a differently-salted hash of the administrator's password. The database password (or information sufficient to reconstruct it) will be kept in memory while the program is running, but absent the administrator password there would be no way to retrieve when the program isn't running, even with full knowledge of the system.

If it's necessary to allow multiple users to access the database, an "add user" button could allow the addition of a user account. When the user types his password, use it to store hashed/encrypted data as with the administrator.

Any user with a debugger would be able to leverage his knowledge of a valid user account and password into knowledge of the database password, but someone who didn't have knowledge of a valid account password wouldn't be able to do anything.

supercat