[Proposal]: System.Security.Cryptography.Aes has some strange APIs, which make it difficult to use. #8594
Replies: 1 comment
-
.NET API questions are handled by the runtime repo. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Aes
,SymmetricAlgorithm
, implements theIDisposable
interface, which is only used to clear array elements. I think it is unnecessary.public int EncryptCbc(ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> iv, Span<byte> destination, PaddingMode paddingMode = PaddingMode.PKCS7)
do not need thePaddingMode
parameter because theAes
class already contains the member variablepublic virtual PaddingMode Padding
.Motivation
When I use an instance of the Aes class, I often find myself deeply puzzled.
Aes
instance allows setting theCipherMode
, such asCipherMode.Cfb
, but at the same time, it provides a member method like:csharp public byte[] EncryptCbc(ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> iv, PaddingMode paddingMode = PaddingMode.PKCS7)
. Why do both of these exist in the same class?Aes
instance allows setting thePaddingMode
. So why is there a need to passPaddingMode
again in the method:public byte[] EncryptCbc(ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> iv, PaddingMode paddingMode = PaddingMode.PKCS7)
Wouldn't it be better to turn this instance method into an extension method?SymmetricAlgorithm
implements theIDisposable
interface, which appears to only be used for clearing array elements. Here is the source code:Is it really necessary to dispose?
Beta Was this translation helpful? Give feedback.
All reactions