Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I store an encryption key for php?

I'm writing a php application that accepts sensitive customer data, and so I need to encrypt it before storing it in a mysql database. I'm going to use mysql's built-in AES functionality to do column-level encryption.

I want to avoid storing the encryption key on the server, and so i'm going to provide a web-page for an administrator to log-in, and enter the encryption key. I want to store this key in memory while the application is running, but never permanently to disk.

What is the best way to do this?

Can I modify the $_SERVER array to store information between requests? Can I store the key with apache in some way? Maybe shared memory?

like image 567
Levi Avatar asked Jul 20 '11 20:07

Levi


People also ask

Where should an encryption key be stored?

The encryption key is created and stored on the key management server. The key manager creates the encryption key through the use of a cryptographically secure random bit generator and stores the key, along with all it's attributes, into the key storage database.

Which encryption is best for PHP?

Secret key encryption (or symmetric encryption as it's also known) uses a single key to both encrypt and decrypt data. In the past PHP relied on mcrypt and openssl for secret key encryption. PHP 7.2 introduced Sodium, which is more modern and widely considered more secure.

Where are AES keys stored?

The AES master key always remains within the secure boundaries of the cryptographic coprocessors. Transport keys protect a key that is sent to another system, received from another system, or stored with data in a file.


1 Answers

Rather than rely on MySQL AES for encryption, why not use PHP's native openssl encryption scheme (a PECL extension). This requires a private and public key, public to encrypt, private to decrypt, and the keys can be kept in separate places.

like image 178
Explosion Pills Avatar answered Sep 27 '22 01:09

Explosion Pills