Mada za sehemu hiiHandling sensitive information in programmingMada 2
- Implementing prevention of hardcoding sensitive information in source code
- Implementing protection of sensitive information in storage
Protecting Sensitive Information in Storage
When we store sensitive information such as passwords, personal details, or financial records, we must protect them from unauthorized access. Data stored without protection can be stolen, copied, or misused if an attacker gains access to the storage medium (computer, phone, or database). In Tanzania, many mobile banking and government systems store personal data that must remain confidential.
1. Encryption
Encryption converts readable data (plaintext) into an unreadable format (ciphertext) using a secret key. Only someone with the correct key can decrypt and read the original data.
Types of Encryption:
- Symmetric Encryption: Uses the same key for encrypting and decrypting data. Example algorithms: AES, DES.
- Asymmetric Encryption: Uses a pair of keys — a public key to encrypt and a private key to decrypt. Example algorithms: RSA.
2. Hashing
Hashing converts data into a fixed-size string of characters (called a hash or digest). It is a one-way process: you cannot reverse a hash to get the original data. Hashing is commonly used to store passwords securely.
Common hash algorithms: MD5, SHA-1, SHA-256
3. Salting
A salt is a random value added to data before hashing. It ensures that even if two users have the same password, their hashes will be different. This protects against rainbow table attacks.
4. Secure File and Database Storage
- Store sensitive files in encrypted directories
- Use database systems that support built-in encryption (PostgreSQL, MySQL)
- Enable encryption at rest for entire drives or storage devices
Consider a simple Tanzanian student registration system that stores user passwords. Follow these steps to store a password securely:
Step 1: Generate a salt
salt = "x7KmP2vN"
Step 2: Combine password with salt
combined = "myPassword123" + "x7KmP2vN"
Step 3: Hash the combined string
hash = SHA256(combined)
Result: a1b2c3d4e5f6... (a fixed 64-character string)
Step 4: Store the salt and hash in the database
| Username | Salt | Password_Hash |
|---|---|---|
| amina | x7KmP2vN | a1b2c3d4... |
When Amina logs in, the system takes her input password, adds the stored salt, hashes it, and compares it to the stored hash. If they match, the password is correct.
Why is this secure?
- The password is never stored in plain text
- Even if the database is stolen, attackers cannot easily recover passwords
- Each user has a unique salt, so they cannot use pre-computed hash tables
- Never store passwords in plain text — always hash them
- Use strong, unique salts for each user
- Choose strong algorithms — avoid MD5 and SHA-1 for passwords (they are outdated)
- Limit access — only authorized code should read encrypted data
- Store keys securely — keep encryption keys separate from encrypted data
- Use industry-standard tools — use verified libraries rather than writing your own encryption
- Storing sensitive data in plain text files
- Using weak hashing algorithms
- Using the same salt for all users
- Hardcoding encryption keys in source code
- Storing encryption keys in the same location as encrypted data
In Tanzania, mobile money services like M-Pesa store millions of customers' personal details and transaction records. When a Tanzanian software developer builds an application that handles customer names, national ID numbers, or account balances, they must encrypt this data in the database. For example, a microfinance app in Dar es Salaam would hash customers' passwords and encrypt their account balances to prevent thieves from stealing data if they break into the office computer. This protects both the customers and the business from financial loss and identity theft.
Jinsi utakavyotathminiwaTathmini ya mchakato · Tathmini ya matokeo · Tathmini ya maarifa
Tathmini ya mchakato
e student should be le to: Identify sensitive 138 information that needs protection in storage. Implement encryption, hashing, or other secure storage techniques. 139
Tathmini ya matokeo
Sensitive information is securely stored using appropriate storage solution that meets industry standards and protects data from unauthorised access.
Tathmini ya maarifa
Methods used: The trainee should explain how to:
- Encrypt sensitive data before storing it in a database or file system.
Principles: The student should explain the principle of:
- Data encryption and decryption to secure information in storage.
- Hashing for storing non-reversible sensitive data securely.
Theories: The trainee should explain: The trainee should explain:
- The role of encryption algorithms in securing data at rest.
- The importance of hashing for password protection and why it differs from encryption.
Detailed knowledge about:
- Tools and frameworks for implementing encryption and hashing.
- Standards and guidelines for data storage security.
- Using secure storage solutions for cloudbased applications.
Swali
What is the primary purpose of encrypting data before storing it?
Ingia ili kuwasilisha jibu lako na lihesabiwe katika umahiri wako.
Ingia ili kufanya mazoeziMwalimu
Umekwama? Niulize chochote kuhusu mada hii.
Ingia ili kumuuliza Mwalimu wa AI wa Sonza kuhusu swali hili.
Ingia ili kuulizaMajadiliano
Hakuna maswali bado