docs
docs copied to clipboard
[Breaking change]: Cryptographic factory methods accepting an algorithm name are obsolete
Description
All of the cryptographic factory methods that accept a string, such as Aes.Create(string) have been declared [Obsolete] with the SYSLIB0045 diagnostic code.
Version
.NET 7 Preview 7
Previous behavior
Calling the member produced no warning. The member calls into CryptoConfig.CreateFromName and casts the result to the return type.
New behavior
In .NET 7, the only direct change is that calls to the member yield a SYSLIB0045 obsoletion warning.
Type of breaking change
- [ ] Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
- [X] Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
Reason for change
In trimmed applications these methods can return null when they wouldn't in non-trimmed applications.
In non-trimmed applications, the exception-based behaviors of these methods occasionally surprises callers, and many of the well-known identifiers are associated with types that are themselves marked [Obsolete].
Recommended action
Calls which pass a constant string should change to either the parameterless factory method, or a strong call to create the appropriate type. For example, a call to Aes.Create("AES") can be replaced with either Aes.Create() or new AesCryptoServiceProvider() (the AesCryptoServiceProvider type is also marked [Obsolete], so Aes.Create() is the preferred replacement).
Calls which pass a non-constant string can either use their own lookup table, or switch to calling CryptoConfig.CreateFromName directly.
Feature area
Cryptography
Affected APIs
M:System.Security.Cryptography.Aes.Create(System.String) M:System.Security.Cryptography.AsymmetricAlgorithm.Create(System.String) M:System.Security.Cryptography.DES.Create(System.String) M:System.Security.Cryptography.ECDiffieHellman.Create(System.String) M:System.Security.Cryptography.ECDsa.Create(System.String) M:System.Security.Cryptography.HashAlgorithm.Create(System.String) M:System.Security.Cryptography.KeyedHashAlgorithm.Create(System.String) M:System.Security.Cryptography.RandomNumberGenerator.Create(System.String) M:System.Security.Cryptography.RC2.Create(System.String) M:System.Security.Cryptography.Rijndael.Create(System.String) M:System.Security.Cryptography.RSA.Create(System.String) M:System.Security.Cryptography.SHA1.Create(System.String) M:System.Security.Cryptography.SHA256.Create(System.String) M:System.Security.Cryptography.SHA384.Create(System.String) M:System.Security.Cryptography.SHA512.Create(System.String) M:System.Security.Cryptography.SymmetricAlgorithm.Create(System.String) M:System.Security.Cryptography.TripleDES.Create(System.String)