Skip to content

Cleanup | Always Encrypted cryptographic algorithm factories#4138

Open
edwardneal wants to merge 4 commits intodotnet:mainfrom
edwardneal:cleanup/alwaysencrypted/02-factories
Open

Cleanup | Always Encrypted cryptographic algorithm factories#4138
edwardneal wants to merge 4 commits intodotnet:mainfrom
edwardneal:cleanup/alwaysencrypted/02-factories

Conversation

@edwardneal
Copy link
Copy Markdown
Contributor

Description

This PR continues some Always Encrypted cleanup and modernization work. It moves more of the internal AE-related classes into the new AlwaysEncrypted namespace, tidying them up as the PR proceeds.

We moved and modernized the public providers which decrypt/encrypt the column master keys in v7.0 GA, and now we proceed to the next stage: the factories which convert a cryptographic algorithm's name to its implementation.

Classes in question:

  • SqlClientEncryptionAlgorithmFactoryList: after being moved to the new namespace, I've simplified the name to EncryptionAlgorithmFactoryList. This class was slightly more complex than it needed to be: it allowed the provider to register its own cryptographic algorithm into a ConcurrentDictionary. This registration process was only ever used to build a static list of one entry, and was never exposed. I've thus replaced it with a simple switch block.
  • SqlClientEncryptionAlgorithmFactory: renamed to EncryptionAlgorithmFactory. No changes beyond comments, this was only ever a base class.
  • SqlAeadAes256CbcHmac256Factory: renamed to AeadAes256CbcHmac256Factory. These are largely just style, comment and whitespace changes. I've also sealed the class and moved the floating AlgorithmVersion constant into the actual algorithm's class.

I'm keeping the column encryption key handling in a separate PR so that any security review can be done on its own. I think these can provide a measurable improvement to Always Encrypted's memory usage.

Issues

None.

Testing

There were a few tests which referred to this using reflection; I've caught those, and they continue to pass. We've got reasonable test coverage for Always Encrypted so I've not added anything else.

This implemented theoretical support for allowing clients to register their own cryptographic algorithms. This was never used, so has been replaced with a static mapping.

Placed its replacement into the AlwaysEncrypted namespace.
Moved into the AlwaysEncrypted namespace, enabled nullability annotations, renamed
This includes:
* Rename to AeadAes256CbcHmac256Factory.
* Enable nullability annotations.
* Whitespace/comment changes.
* Move the version constant into the algorithm itself (and out of the factory.)
* Minor improvement to StringBuilder concatenation.
@edwardneal edwardneal requested a review from a team as a code owner April 6, 2026 00:27
@github-project-automation github-project-automation bot moved this to To triage in SqlClient Board Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

1 participant