2

I have a field that will contain a user specific information that I want to encrypt when it gets placed inside the database. That information is later being accessed ONLY by me (the admin). What is the best way to have that information encrypted inside the database and view-able by me within the admin area?

The field will contain only numbers. Site built with PHP, MySQL, an example code?

Johan Larsson
  • 175
  • 5
  • 17
  • The create it with your own algorithm like `add 123 at front of the number add 890 at the end of the number and middle of the number add some xxx` – Miqdad Ali Oct 05 '12 at 11:09
  • 3
    http://stackoverflow.com/questions/1289061/best-way-to-use-php-to-encrypt-and-decrypt – Aurimas Ličkus Oct 05 '12 at 11:13
  • What speaks against using one of the available encryption algorithms in php? Just encrypt the data before handing it over to the database engine and decrypt it when querying. – arkascha Oct 05 '12 at 11:19
  • Please do not follow @MiqdadAli's advice. Julius Caesar used that kind of encryption around 60 BC, but there is a good reason we don't do that anymore... BTW; are you sure encryption is needed in the first place? When no-one else but you has access to the database (which has a good security by default) I wouldn't bother to much, just be sure your scripts don't give access to the specific table or field. When creditcard credentials are concerned you still might want to encrypt the data – giorgio Oct 05 '12 at 11:33
  • @giorgio I just mean that he should develop his own encryption method :) – Miqdad Ali Oct 08 '12 at 03:27

2 Answers2

0

Public/Private key pair encryption

What you're looking for is Public/Private key encryption. For implementing it, you can follow this link: http://i.amniels.com/mysql-database-encryption-using-public-private-keys

Essentially what this does is encrypt the data using a public key. Public keys can be distributed and is not hidden.

This data will though, only be decryptable of you posses the private key. They private key unlocks what the public key encrypts.

Kao
  • 2,242
  • 3
  • 22
  • 31
0

Best way to use PHP to encrypt and decrypt?

This archived question explains how to encrypt you data pre storage and decrypt it after retrieval enabling you to modify / display it as plain text.

Mcrypt Reference may also come in use.

Hope this helps

Community
  • 1
  • 1
Phil
  • 463
  • 3
  • 9