Your .NET application stores encrypted credit card numbers in a SQL Server database. You must be able to retrieve and decrypt the numbers when necessary. Which cryptography provider should you use to encrypt the data?

Difficulty: Medium

Correct Answer: AesCryptoServiceProvider

Explanation:


Introduction / Context:
Applications that handle sensitive data such as credit card numbers must use strong cryptography to protect that information in storage. At the same time, the application must be able to decrypt the data when authorized operations require using the original values. In the .NET Framework, different cryptography providers support different algorithms and usage patterns. Understanding which providers are reversible encryption algorithms and which are one way hashing algorithms is critical for securely storing and later retrieving sensitive values.


Given Data / Assumptions:

    The application uses .NET Framework 4 and a SQL Server database.

    Credit card numbers are stored in encrypted form in the database columns, not as plain text.

    Authorised features of the application must decrypt and use the original card numbers, so the encryption must be reversible.

    You are choosing between cryptography providers such as AES, DSA, MD5, and SHA1.

    Security and compliance best practices recommend strong, modern algorithms.


Concept / Approach:
AesCryptoServiceProvider implements the Advanced Encryption Standard, a symmetric encryption algorithm that supports both encryption and decryption with the same key. This makes it suitable for scenarios where data must be recovered. DSACryptoServiceProvider implements a digital signature algorithm, not general purpose encryption. MD5CryptoServiceProvider and SHA1CryptoServiceProvider implement hashing algorithms that are one way and cannot be reversed to obtain the original input, so they are appropriate for password verification but not for recoverable credit card storage. Therefore, to encrypt credit card numbers and later decrypt them, you should use AesCryptoServiceProvider or an equivalent symmetric encryption provider.


Step-by-Step Solution:
1. Recognize that you need a reversible algorithm because the application must be able to retrieve the original credit card numbers for legitimate purposes. 2. Exclude hashing algorithms such as MD5 and SHA1, which produce fixed length digests that cannot be reversed. 3. Exclude DSACryptoServiceProvider because DSA is intended for digital signatures and not for encrypting arbitrary data for later decryption. 4. Select AesCryptoServiceProvider, which provides a strong, modern symmetric encryption algorithm widely recommended for sensitive data at rest. 5. Implement proper key management, initialization vectors, and secure storage of keys to ensure that the encrypted data remains protected even if the database is compromised.


Verification / Alternative check:
You can test AesCryptoServiceProvider by encrypting a sample credit card number and then decrypting it using the same key and initialization vector. The decrypted output should match the original number exactly. Documentation for AesCryptoServiceProvider explains that it supports both Encrypt and Decrypt operations and is suitable for protecting data stored in databases.


Why Other Options Are Wrong:
DSACryptoServiceProvider is designed for signing and verifying data, not for symmetric encryption and decryption of arbitrary values such as credit card numbers.
MD5CryptoServiceProvider and SHA1CryptoServiceProvider generate one way hashes that are not reversible, so they cannot be used when the original data must be recovered from the stored value.


Common Pitfalls:
One pitfall is using hashing for data that must be decrypted later; hashes are appropriate only when you need to verify equality, such as password checking, but not when original values are needed. Another is using outdated or weak algorithms such as MD5 or SHA1 for security sensitive contexts, which modern cryptographic guidance warns against. Always pair a strong symmetric algorithm such as AES with proper key management and secure coding practices.


Final Answer:
You should use AesCryptoServiceProvider so that credit card numbers can be encrypted and later decrypted securely.

More Questions from Microsoft Certification

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion