Mysql: data encryption and decryption

Does mysql provide a mechanism for storing and receiving encrypted data? I do not mean passwords, I mean real lines.

I would like to encrypt the string, save in mysql and then get the decrypted string later.

So, I know that there are AES_Encrypt and decrypt functions. But they ask for the key. (this is normal), but I wonder if you call these functions and use your user password as a key. Or something else super simple.

Also, is there a simple wrapper for AES_Encrypt and decryption functions in Rails? Or do you need to create a query manually?

+4
source share
3 answers

If I understand you, then all you need is a method of generating an AES key from your (or other) user password?

Don't you ask: "Is there an easy way to generate an AES key from line 5-20char?"

As you noticed, other tools are already installed in mysql: http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html

You can also find some ideas in this here on SO.

+3
source

You can simply perform encryption functions:

select aes_encrypt('MyData',Password('MyPassword')) 

and back.

 select Aes_decrypt( aes_encrypt('MyData',Password('MyPassword')) , Password('MyPassword')) 
+5
source
 $pass = $_POST['pass']; $sql = "INSERT INTO testperson (name,password,contact) VALUES('$name',md5('$pass'),$cont)"; 

Just write md5 before the login you want to encrypt, such as a password.

-2
source

Source: https://habr.com/ru/post/1305725/


All Articles