Skip to content

Implement RSA Encryption with Standard Keys#32

Merged
ldsenow merged 8 commits intomainfrom
claude/rsa-key-operations-011CUYvsS13HdootLX3eB6As
Oct 28, 2025
Merged

Implement RSA Encryption with Standard Keys#32
ldsenow merged 8 commits intomainfrom
claude/rsa-key-operations-011CUYvsS13HdootLX3eB6As

Conversation

@ldsenow
Copy link
Contributor

@ldsenow ldsenow commented Oct 28, 2025

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Security fix
  • Test improvements

Related Issues

Fixes #
Closes #
Related to #

Changes Made

Summary of Changes

Technical Details

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Test vectors from official specifications included (if applicable)
  • All existing tests pass
  • New tests pass

Test Scenarios Covered

Manual Testing

Cryptographic Implementation Checklist

  • Implementation follows published standard (RFC, NIST, ISO)
  • Reference to specification included in code comments
  • Official test vectors included and passing
  • Constant-time operations used where necessary
  • Memory securely cleared after use
  • Input validation is comprehensive
  • Security warnings documented where appropriate
  • No unsafe code (or well-justified if necessary)

Standard/Specification:

Documentation

  • XML documentation added for new public APIs
  • README.md updated (if needed)
  • CHANGELOG.md updated
  • Code comments added for complex logic
  • Usage examples provided

Code Quality

  • Code follows project style guidelines
  • EditorConfig settings applied
  • No compiler warnings introduced
  • Code has been self-reviewed
  • Code is DRY (Don't Repeat Yourself)
  • Naming conventions followed

Breaking Changes

Breaking Changes Description

Migration Guide

Performance Impact

  • No performance impact
  • Performance improved (include benchmark results)
  • Performance decreased (justified by security/correctness)
  • Not applicable

Benchmark Results (if applicable)

<!-- Paste benchmark results here -->

Security Considerations

  • No security impact
  • Security improved
  • New security considerations (documented)
  • Not applicable

Security Impact Description

Deployment Notes

  • No special deployment needed
  • Requires configuration changes
  • Requires database migrations
  • Other (describe below)

Screenshots / Logs

Checklist

  • I have read the CONTRIBUTING.md guidelines
  • My code follows the project's code style
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have updated the CHANGELOG.md file

Additional Context


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT License.

… size

This commit introduces comprehensive RSA encryption/decryption functionality
with enhanced security through conservative key size requirements:

Changes:
- Increased minimum RSA key size from 1024 to 2048 bits per NIST recommendations
- Removed 1024-bit from accepted key sizes (now: 2048, 3072, 4096, 8192, 16384)
- Added RsaEncryptionService with support for:
  - Key generation with configurable key sizes (default: 2048-bit)
  - Public key encryption with PKCS#1 and OAEP padding modes
  - Private key decryption with matching padding support
  - Async operations for CPU-bound encryption/decryption
  - Proper input validation and error handling
  - Secure memory management for sensitive key material
- Updated RsaDigitalSignatureServiceTests to use 2048-bit keys
- Added comprehensive test suite for RsaEncryptionService covering:
  - Key generation and derivation
  - Encryption/decryption with multiple padding modes
  - Round-trip data preservation
  - Security validation (tampered data detection)
  - Edge cases (max message size, different key sizes)
  - Async operation correctness

Security rationale:
- 1024-bit RSA is deprecated and considered insecure by modern standards
- NIST recommends 2048-bit minimum for current use
- Default OAEP padding provides better security than PKCS#1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ptionService

Added the HeroCrypt.Abstractions namespace import to resolve compilation
error for ISecureMemoryManager type reference.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rvice

Added type alias 'SystemHashAlgorithmName' for System.Security.Cryptography.HashAlgorithmName
to disambiguate from HeroCrypt.Abstractions.HashAlgorithmName. Updated all references
throughout the RsaEncryptionService to use the aliased type.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…um RSA keys

Updated test cases to reflect the new 2048-bit minimum key size requirement:
- Renamed GenerateRsaKeyPair_1024Bits_ReturnsValidKeyPair to use 2048 bits
- Updated GenerateRsaKeyPair_InvalidKeySize_ThrowsException to test with 1024 bits (now invalid)
- Updated expected error message from "1024 bits" to "2048 bits"
- Updated GenerateRsaKeyPairAsync_WorksCorrectly to use 2048-bit keys

These changes align with the enhanced security requirements enforced in InputValidator.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updated RSA key size validation tests to reflect the new 2048-bit minimum:
- Removed 1024 from ValidateRsaKeySize_ValidSizes_DoesNotThrow test cases
- Added 3072 as a valid size (2048, 3072, 4096 now tested)
- Added 1024 to ValidateRsaKeySize_InvalidSizes_ThrowsArgumentException (now correctly rejected)

These changes align with the enhanced security requirements enforced in InputValidator.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ptionService

Removed the unused _memoryManager field and memoryManager constructor parameter.
The service already uses SecureMemoryOperations.SecureClear() directly for
memory clearing, and ISecureMemoryManager is for buffer allocation/pooling
which is not needed for RSA operations.

This eliminates an unnecessary optional dependency that was never used.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rvices

Removed the unused _memoryManager field and memoryManager constructor parameter
from three services that declared but never used it:
- Blake2bHashingService
- CryptographicKeyGenerationService
- RsaDigitalSignatureService

These services don't need ISecureMemoryManager (which is for buffer allocation/
pooling). They either don't handle sensitive memory or use SecureMemoryOperations
directly for memory clearing.

This eliminates unnecessary optional dependencies across the codebase.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ldsenow ldsenow merged commit 61c76bc into main Oct 28, 2025
31 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments