Skip to content

[API Proposal]: AesGcm/AesCcm.KeySize #72191

Closed

Description

@sdrapkin

API Proposal

namespace System.Security.Cryptography;

public partial class AesGcm
{
    public int KeySize { get; }
}

public partial class AesCcm
{
    public int KeySize { get; }
}

API Usage

void OnlyAesGcm256(AesGcm gcm)
{
    const int ALLOWED_KEY_SIZE = 256;
    if (gcm.KeySize != ALLOWED_KEY_SIZE) throw new CryptographicException();
    // do stuff
}

Alternative Designs

No response

Risks

New APIs. No breaking changes/risks. No performance regressions/impacts.

Activity

  1. added
    api-suggestion
    on Jul 14, 2022
  2. ghost added
    untriaged
    on Jul 14, 2022
  3. bartonjs commented on Jul 20, 2022

    @bartonjs
    Member

    The reason for providing the NonceSizeBytes and TagSizeBytes is mainly to bring up that these have variability of implementation in the ecosystem at large; we've generally not found evidence that anyone actually ever reads them.

    We intentionally don't allow retrieving the key itself from these new types, but adding an instance KeySize property seems reasonable to me.

  4. added this to the Future milestone on Aug 2, 2022
  5. ghost removed
    untriaged
    on Aug 2, 2022
  6. sdrapkin commented on Mar 21, 2023

    @sdrapkin
    Author

    Can this be added to .NET 8?

  7. bartonjs commented on Apr 27, 2026

    @bartonjs
    Member

    I've removed the KeyByteSizes segment from the proposal and marked it ready-for-review. Given that every other KeySize property we have is reporting in bits, I think we should continue with that here, so I updated the sample accordingly.

  8. added
    api-ready-for-review
    on Apr 27, 2026
  9. changed the title [-][API Proposal]: AesGcm/AesCcm.KeyByteSizes, AesGcm/AesCcm.KeySize[/-] [+][API Proposal]: AesGcm/AesCcm.KeySize[/+] on Apr 27, 2026
  10. removed
    api-suggestion
    on Apr 27, 2026
  11. bartonjs commented on Jun 23, 2026

    @bartonjs
    Member

    Video

    • Changed KeySize to KeySizeInBytes
    namespace System.Security.Cryptography;
    
    public partial class AesGcm
    {
        public int KeySizeInBytes { get; }
    }
    
    public partial class AesCcm
    {
        public int KeySizeInBytes { get; }
    }
  12. added
    api-approved
    and removed
    api-ready-for-review
    on Jun 23, 2026
  13. sdrapkin commented on Jun 24, 2026

    @sdrapkin
    Author

    It's great to see some progress (4 years later).

  14. vcsjones commented on Jun 24, 2026

    @vcsjones
    Member

    Implemented by #129770

  15. locked and limited conversation to collaborators on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-System.Security

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions