Saltar al contenido

Lección 19 · Security and Privacy

Protecting Data: Encryption, Masking and Incidents

Compare encryption, hashing, masking, tokenization, pseudonymization and anonymization, protect test data, and prepare an incident response for data breaches.

Access control decides who gets in. Other protections limit the damage if someone gets in anyway, or if data has to be shared. This lesson compares the main techniques and shows what to do when something goes wrong. It is an overview, not a replacement for your security team.

Encryption

Encryption turns data into unreadable form that can be reversed with the right key.

  • In transit: protects data moving across networks, for example with TLS.
  • At rest: protects stored disks, databases and backups.
  • Field or application level: encrypts specific sensitive values, so even someone with database access cannot read them without the key.

Encryption is only as strong as key management. Keep keys apart from the data, limit who can use them, rotate them according to policy and plan for key loss: if you lose the key, the data is gone. Use well-established libraries and services; never invent your own encryption.

Hashing, masking, tokenization and more

Transforming values

Encryption Reversible with a key
Hashing One-way digest
Masking Hides part or all
1 / 2

Hashing produces a fixed-length digest that is not meant to be reversed. Passwords must be stored with a slow, salted password hashing function built for that purpose, not a plain fast hash. Hashing an email or phone number is weak protection by itself, because an attacker can hash guesses and compare.

Tokenization replaces a sensitive value with a token; the mapping is held in a protected service. Masking shows only part, such as the last four digits. Pseudonymization replaces identifiers so records cannot be linked to a person without additional information kept separately. Under the EU GDPR, pseudonymized data is still personal data. Anonymization aims to make identification no longer reasonably possible. It is difficult to achieve, because combining other data can re-identify people, so test claims carefully and get expert advice.

See the weaknesses

This example creates keyed pseudonyms with an HMAC, which means attackers cannot compute them without the secret key. The key is written in the code only for the demo; real keys belong in a secret manager.

Python Mask and pseudonymize values

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two emails give the same pseudonym, which is useful for joining datasets and also means records can still be linked. The card numbers shown are common test-style values, not real cards.

Protect non-production data

Test and development systems are often less protected than production. Prefer synthetic data. If you must use copies of real data, mask it and apply production-level controls to anything still sensitive. Check that masked data keeps the formats your tests need, and verify that free text fields do not leak details.

The same care applies to AI tools. Before pasting data into an AI system, check your organization's rules, the provider's data terms and whether you are allowed to send that information at all.

Prevent and detect

  • Patch systems and require multifactor authentication.
  • Remove secrets from code; use a secret manager.
  • Watch for unusual access, such as large exports at odd hours.
  • Limit downloads and external sharing of restricted data.
  • Train people to recognize phishing and to report mistakes quickly.

When a breach happens

A data breach can be an attack or an honest mistake, such as emailing a file to the wrong person. Prepare before you need to:

TEXT
Data incident checklist (adapt to your organization)
[ ] Report to the security and privacy contact immediately
[ ] Record time discovered, what is known, who is involved
[ ] Contain: revoke access, recall or isolate, preserve evidence
[ ] Assess: which data, how many people, what harm is likely
[ ] Decide on notifications with legal and privacy advisers
[ ] Communicate honestly; do not speculate
[ ] Fix the cause and review the response

Many laws set notification deadlines. For example, under the EU GDPR, a controller must generally notify the supervisory authority within 72 hours after becoming aware of a personal data breach, unless the breach is unlikely to result in a risk to people's rights and freedoms. Other rules and exceptions apply, and other countries differ, so confirm the current requirements with qualified advisers. This is education, not legal advice.

Never delay reporting while you try to fix an incident alone or to be sure of every detail. Early reporting gives specialists time to act, and deadlines may already be running.

Choosing a technique: a worked example

A fictional university wants an external consultant to study course completion. Sending the full student table would expose far more than needed. The team steps through choices:

  1. Is individual data needed? For overall completion rates, aggregated counts may be enough.
  2. If individual rows are needed, remove fields that the study does not use, such as names, addresses and contact details.
  3. Replace student numbers with keyed pseudonyms, keeping the key inside the university.
  4. Generalize values that could single someone out, such as exact birth date to age band.
  5. Check small groups. If only one student on a course is over 60, an age band can still identify that person.
  6. Agree terms, access method, security and deletion date in writing.

The result may still be personal data, so it keeps the required protections. Every step reduces risk; none of them removes the need for judgment.

Remember the people

Many incidents involve ordinary actions: a wrong recipient, a file shared with a public link or a lost laptop. Technical settings help, such as warnings on external sharing, link expiry and device encryption. A culture where people report mistakes quickly, without fear of automatic blame, helps just as much.

Try it yourself

For one fictional dataset, list who needs it, which columns they need and which technique protects each remaining sensitive column.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Which statement about pseudonymized data is correct under the EU GDPR?

    Because it can be linked back using additional information, it remains personal data.
  2. 2. Why is a plain hash of a phone number weak protection?

    Small value spaces can be searched by guessing.
  3. 3. You accidentally emailed a customer file to the wrong person. What should you do first?

    Quick reporting allows containment and meeting any legal deadlines.

Summary

  • Encrypt in transit and at rest, and manage keys carefully.
  • Hashing, masking, tokenization, pseudonymization and anonymization solve different problems.
  • Protect test data and be careful with external tools.
  • Prepare an incident process and report early.
  • Confirm legal duties with qualified advisers.

Next: Privacy by Design and Individual Rights

Tu progreso se guarda en este navegador. No necesitas una cuenta.