mysql alternative to AES for encryption - so can't decrypt value - mysql

I'm currently using AES encryption in mysql (in a Silex PHP app) and would like to change to using a form of encryption where we can't decrypt the value - in order to lessen liability concerns. I believe the MD5 can be used for this purpose, but I've read that MD5 is not terribly secure. Is there an approach that you'd suggest?

Related

Is it overkill to encrypt an already hashed BCrypt password?

I'm using BCrypt to hash my passwords on the server side. Before I store it in my MySQL database, would it be overkill to encrypt my hashed-BCrypt password or would storing the hash directly in the database suffice?
This website advises to encrypt passwords after hashing them:
As long as an attacker can use a hash to check whether a password
guess is right or wrong, they can run a dictionary or brute-force
attack on the hash. The next step is to add a secret key to the hash
so that only someone who knows the key can use the hash to validate a
password. This can be accomplished two ways. Either the hash can be
encrypted using a cipher like AES, or the secret key can be included
in the hash using a keyed hash algorithm like HMAC.
EDIT: I'm coding in Java. I'm trying to gauge whether the added layer of protection vs. speed performance of read & retrieval of passwords for user logins is worth it or not.
This would indeed increase security, but it is good to know what exactly you gain with encryption.
Encrypting the password-hash can protect weak user passwords from a
dictionary attack, in the special case, where the attacker has
read-access to the database (containing the hashes) but does not have
access to the source code with the key/pepper.
This situation is not so uncommon as one would think, typical scenarios would be SQL-injection, thrown away backups, discarded servers...
To be able to brute-force for passwords one needs the server side key, which was used to encrypt the password-hashes. This means, being able to read the hashes from the database is not enough anymore, one needs additional privileges to read the key from the server. Getting privileges on the server is much more difficult than being able to read the database.
Crackstation is a good site for advice. At the end of my own tutorial about safely storing password I try to explain the details of this password-hash encryption.

MySQL- How to implement server-side password hashing

I am creating a database and I need to store user passwords. I am already using bcrypt to hash the passwords on the client side, but I have read that only hashing on the client side makes the hash essentially equivalent to a password as far as the database is concerned. I'd like to hash the passwords (which are now hashes) again before they are stored in the database. Do I have to use a method native to MySQL like SHA2(pwd), or is there a way to use bcrypt on the server?
Bcyrpt is a good call here, but you should be doing the hashing on the server end, not the client. The client can't know all the information it needs to produce a hash you can verify is correct, only the server has that information.
What you need to do is pass through the password securely, such as over HTTPS, and hash it there in your application layer. MySQL alone does not have the functions necessary to do proper password hashing. SHA2 is completely inadequate, it's a high-speed hash by design which makes it immediately unsuitable. Password hashing algorithms are deliberately slow to make brute-forcing passwords painfully expensive.

How to encrypt user passwords for forum registrations?

What is the most secure way to encrypt user passwords for phpBB or MyBB forum registrations? I don't want anyone to be able to access the user passwords, not even those who administrate the MySQL database, and also if someone manages to hack the database to not be able to view them. I want only the users who register to know their passwords.
I completely agree with the response Federico Razzoli, except for one thing. Indeed, hashing must be performed upstream, in any case not at the database level (so your question is probably off topic).
However simply using a hash function is not sufficient in terms of security. You remain vulnerable to dictionary attacks, rainbow table attacks, and some attacks by frequency analysis. It is essential to at least use a cryptographic salt.
However, the best is to use a key derivation function designed to store passwords. I suggest you to look at PBKDF2 (hash_pbkdf2 with PHP), bcrypt (password_hash with PHP, which by default uses a judicious algorithm, bcrypt currently) or scrypt.
Finally, your question suggests that you use phpBB, this forum engine should normally deal alone with the secure storage of passwords.
You can use SHA512.
I see that you used the "mysql" tag. Please, don't use the SHA2() SQL function, or any other SQL hash function. If you do so, the plain strings will be sent across the net, and probably written in some logs.
Use the PHP hash() function instead, and specify 'sha256' as first parameter.

Does mysql have asymmetric encryption capabilities?

My Question is simple - is there a build in functionality, like AES_ENCRYPT / AES_DECRYPT, for asymmetric (public / private key) encryption in MySQL?
Sadly, I only find answers that involve PHP (to encrypt it in php), and stuff like that. I would like to keep it in MySQL, since the whole application logic is handled by procedures - and I would like to avoid ruining that by bringing in external languages to solve this issue.
There is no functionality for RSA encryption within MySQL. it's sort of an odd use case, so the MySQL folks probably haven't seen fit to implement it
You'll have to do the RSA operations in the application layer, and pass the results into your procedures, unless you fancy implementing RSA within MySQL yourself (which I really cannot advise at all)
What you can do is something like this; Make a shared secret between multiple users using their pub/priv keys, then use that shared secret as the AES symetric key to unlock the data in mysql.
What this means is that you can utilize mysql's inbuilt AES encrypt function for convenience while still maintaining secure data given that you will never know the shared secret.
eg:
Also you can try reading this enter link description here
I am very much agree to #Peter Elliott. But as part of answer I would like to add that MySQL Enterprise Encryption provide that kind of facility such as :
MySQL Enterprise Encryption gives DBAs and Developers the tools they need for:
Asymmetric Public Key Encryption (RSA) Asymmetric Private Key
Decryption (RSA) Generate Public/Private Key (RSA, DSA, DH) Derive
Symmetric Keys from Public and Private Key pairs (DH) Digitally Sign
Data (RSA, DSA) Verify Data Signature (RSA, DSA) Validation Data
Authenticity (RSA, DSA)
For more information you can visit MySQL Enterprise Encryption, I hope this will be helpful to you.

Is the MySQL password function vulnerable to this?

Is storing a password in the DB using MySQL's password function just as bad as this?
http://money.cnn.com/2012/06/06/technology/linkedin-password-hack/?source=linkedin
The problem with SHA-1 is that it translates the same text the same way each time. So if your password is "password" and your friend's password is also "password," they will be hashed exactly the same way. That makes reversing the process to uncover the original password significantly easier.
I know it says SHA-1, but obviously any unsalted one way hash would have the same issue.
Is storing a password in the DB using MySQL's password function just as bad as this?
Yes.
Generally speaking you want to use a method that includes a salt, preferably unique for each user, and is slow to run to prevent brute force cracking. Bcrypt is the currently recommended way to go when storing passwords because it is intentionally (relatively) slow to create.
MySQL documentation says that you shouldn't be using the PASSWORD() function in your own application:
The PASSWORD() function is used by the authentication system in MySQL
Server; you should not use it in your own applications.
Internally, MySQL's PASSWORD() function utilizes SHA1(2), that's SHA1 twice. However, it doesn't utilize a salt. So, yes, it's still vulnerable to rainbow table attacks.