Imagine a table in a database in MySQL that holds millions of telephone and cellphone numbers that relate to itemized billing for VoIP and Cellular carriers.

All of these numbers are in VARCHAR fields and they are clearly visible to anyone who has access to the database. These numbers need to be like this because they are read out to form parts of reports and because there are millions of records, it's quite resource intensive to sift through it all.

I'm in search of ways to store these numbers in a way that would be well... Safer.

Say for instance, the database got compromised and someone else gained access to this information... They would have millions of active numbers and could really make havoc out of that.

So to avoid this situation (it's not physically possible at the moment as we're on a closed network) in the future, what would be the right thing to do with all of these numbers?

I need a way to make then like a hash and then unhash them on request... The problem is the resources involved in this, any one number could have thousands of records so this would end up being quite resource intensive... There must be a more suitable solution for something like this?

I'd like to say that I am really looking for some opinions, feedback, input or guidance from some professionals with relative experience. I'm sure that in the manual there is something somewhere that covers something sort of like this... But I cannot seem to find it so I would like some insight into how to deal with this the correct way!

Thank you.

EDIT: I'd like to note that this question is not about server security, it is about information security... When i look at the database and see raw numbers it just feels wrong... Is it wrong or am i just being paranoid?

1 Answer 1


If you store encrypted data in the database, the data is not understandable anymore without a layer of code on top. This might seem like a good move, but if one takes a closer look, it complicates things and does not provide more security.

An example which becomes a lot more complicated: "Compute the number of phone numbers with a special area code". How to do this in a normal DB? Well something like SELECT COUNT(*) FROM phonenumbers WHERE phonenumber LIKE "XZY%" will work. How to do this, if the database cannot understand its own data? Transfer everything to the application, decrypt it and compute the result there. That can obviously be really cumbersome with large databases. Basically all advantages one receives through using a DBMS are nullified.

Why this is not more secure? One does not even have to hack your database anymore, it is enough to hack the application. Likely this is easier, since the application uses a lot of custom code. Further the firewall will allow access to the application servers, while it will likely prohibit access to database servers from outside.

What to do instead? Secure the database server and restrict access to sensitive data. You can (should) create a dedicated area for sensitive data, which can only be accessed with dedicated database accounts. This credentials should be used rarely in your application, and should not be handed over easily to e.g. developers. You could even set up an own dedicated isolated database server for such sensitive information.

  • 1
    You could perhaps (if not too sensitive) store what @GhostGamlber suggests as a separate field (country_code, area_code...), although in my country (Ireland) there are no area codes associated with mobiles, unlike say in America (at least for some mobile phones AFAIK). Then, you can severely restrict access to the end numbers on a need-to-know basis.
    – Vérace
    Oct 8, 2014 at 10:04
  • Thanks for your input here GhostGambler, that does make sense to me however i'm going to have to process the pro's and cons and see what would be the absolute best solution. You've given me a lot to think about. Oct 8, 2014 at 10:10
  • @Vérace That would indeed be a good solution too.. I wouldn't need to block access to the entire number, just most of it. Not really sure that we'd have a use for a feature like this though so it really depends. It is a good point though, thank you for the input! Oct 8, 2014 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.