I have a quick little app that steps through the possible symmetric encryption methods. I get them with the following line:
private static List<Type> GetAlgorithmTypes
{
get { return Assembly.GetAssembly(typeof(SymmetricAlgorithm)).GetTypes().Where( type => type.IsSubclassOf(typeof(SymmetricAlgorithm))).ToList(); }
}
As you can see when i run this, AesCryptoServiceProvider is not a member of this group, even though it inherits from AES, which does belong to SymmetricAlgorithm and shows up in my list. This wouldn't be so much of a problem, i can manually add the provider in the group if i have too, but then if i try to retrieve this type by its name:
Type t = Type.GetType("System.Security.Cryptography.AesCryptoServiceProvider");
i get a null object for AesCryptoServiceProvider, but not for any of the other items in the group.
This is really strange, and i'm wondering if anyone has any ideas. It's kinda making me need to use tripleDES because of this (since my machines are all running the FIPS compliance requirement).
Thanks for any help!
SymmetricAlgorithm is in mscorlib.dll, AesCryptoServiceProvider is located in System.Core.dll
By getting the assembly based on the SymmetricAlgorithm type you are getting the mscorlib assembly which does not contain AesCryptoServiceProvider.
You might want to pinvoke CryptEnumProviders, to get a list of available CSPs, then you can use CryptoConfig.CreateFromName(...) to create an instance of that CSP.
You could try something like this, it will find the type if its assembly loaded in the current AppDomain.
var types = AppDomain.CurrentDomain.GetAssemblies()
.Select(
a => a.GetTypes()
.Where( t => typeof(SymmetricAlgorithm).IsAssignableFrom(t) )
)