Search
Database

SQL Azure: Securing Your Data With Encryption

First published Rewritten 1 min readBy Programming4us Editorial Team

Moving a database to the cloud raises an obvious question: who can read the data? In the early SQL Azure service, protection relied mainly on encrypted connections and application-level encryption, because several on-premises SQL Server encryption features were not available.

Encryption in transit

SQL Azure required encrypted connections. Clients should connect with Encrypt=True and TrustServerCertificate=False in the connection string so the server certificate is validated, preventing man-in-the-middle attacks:

Server=tcp:myserver.database.windows.net,1433;Database=Sales;
User ID=appuser@myserver;Password=...;Encrypt=True;TrustServerCertificate=False;

What was missing at first

  • Transparent Data Encryption (TDE), which encrypts data files at rest in SQL Server 2008 Enterprise, was not available in early SQL Azure.
  • Cell-level encryption with certificates and symmetric keys (ENCRYPTBYKEY) was not supported, because the service did not allow creating certificates in the database at the time.

Encrypting sensitive columns in the application

The recommended approach for highly sensitive data, such as national ID numbers or card data, was to encrypt it in the application before sending it to the database:

  1. Use a strong algorithm from the .NET Framework, for example AES via AesCryptoServiceProvider.
  2. Store the ciphertext in a varbinary column.
  3. Keep the keys outside the database, in a protected configuration store or key management system, never in the same database.
  4. Decrypt only in the application tier for authorised users.

The trade-off: encrypted columns cannot be searched or indexed by value. A common workaround is storing a keyed hash (HMAC) of the value in a separate column for equality lookups.

Hashing passwords

Never encrypt passwords for storage; hash them with a salted, slow algorithm in the application.

Today's equivalent

Azure SQL Database now enables TDE by default for all new databases, supports customer-managed keys in Azure Key Vault, and offers Always Encrypted (including secure enclaves), which encrypts columns client-side so the database never sees plaintext. TLS 1.2 or later is enforced for connections.