Skip to content

🚀 [Feature]: Add support to run ConvertFrom-SodiumSealedBox without a public key#30

Merged
Marius Storhaug (MariusStorhaug) merged 9 commits intomainfrom
noPublicKey
Apr 18, 2025
Merged

🚀 [Feature]: Add support to run ConvertFrom-SodiumSealedBox without a public key#30
Marius Storhaug (MariusStorhaug) merged 9 commits intomainfrom
noPublicKey

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

@MariusStorhaug Marius Storhaug (MariusStorhaug) commented Apr 18, 2025

Description

This pull request introduces a new function to derive public keys from private keys, making the public key parameter optional during decryption.

Updates to cryptographic functionality:

  • Parameter name cleanup in Sodium.cs:
    • Updated method parameter names in the Sodium class to use descriptive names (publicKey and privateKey) for better readability and consistency.
  • New cryptographic function in Sodium.cs:
    • Added crypto_scalarmult_base, a function for deriving Curve25519 public keys from private keys.

Enhancements to decryption usability

  • New Get-SodiumPublicKey function:
    • Introduced a function to derive a public key from a private key using the crypto_scalarmult_base method, supporting both base64 and byte array outputs.
  • Make public key optional in ConvertFrom-SodiumSealedBox.ps1:
    • Made the PublicKey parameter optional. If not provided, the public key is derived from the private key using the new Get-SodiumPublicKey function.

Improvements to tests:

  • Expanded test coverage in Sodium.Tests.ps1:
    • Added tests for decryption without providing a public key, ensuring functionality when only the private key is supplied.
    • Introduced tests for the new Get-SodiumPublicKey function, including validation of derived public keys and error handling for invalid private keys.
    • Refactored existing tests to use consistent variable names ($encryptedMessage) and streamlined error handling assertions.

Type of change

  • 📖 [Docs]
  • 🪲 [Fix]
  • 🩹 [Patch]
  • ⚠️ [Security fix]
  • 🚀 [Feature]
  • 🌟 [Breaking change]

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

…tFrom-SodiumSealedBox` to improve clarity and add new test cases for decryption without public key
Copilot AI review requested due to automatic review settings April 18, 2025 11:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (1)
  • tests/Sodium.Tests.ps1: Language not supported

…d add `crypto_scalarmult_base` extern declaration
…from private key if not provided and adjust parameter attributes for clarity
…erivation from private key and error handling for invalid keys
…t` for base64 decoding and improve error handling for key validation; enhance `Get-SodiumPublicKey` with base64 output option and refactor for clarity.
…ntation and return raw byte array instead of UTF8 string when base64 option is not specified.
…ey as a byte array; update `ConvertFrom-SodiumSealedBox` to utilize new byte array option for public key retrieval.
…utput changes; modify example outputs for clarity and accuracy regarding byte array return.
@MariusStorhaug Marius Storhaug (MariusStorhaug) changed the title 🩹 [Patch]: Add support to run ConvertFrom-SodiumSealedBox without a public key 🚀 [Feature]: Add support to run ConvertFrom-SodiumSealedBox without a public key Apr 18, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The PR introduces support for running ConvertFrom-SodiumSealedBox without a public key by enabling the derivation of the public key from the private key. Key changes include:

  • Renaming parameters in cryptographic functions (pk/sk → publicKey/privateKey) for improved clarity and consistency.
  • Adding a new function, crypto_scalarmult_base, to derive Curve25519 public keys from private keys.
  • Updating tests to validate decryption behavior when the public key is omitted.
Files not reviewed (3)
  • src/functions/public/ConvertFrom-SodiumSealedBox.ps1: Language not supported
  • src/functions/public/Get-SodiumPublicKey.ps1: Language not supported
  • tests/Sodium.Tests.ps1: Language not supported

@github-actions
Copy link
Copy Markdown

Module Sodium - 2.2.0 published to the PowerShell Gallery.

@github-actions
Copy link
Copy Markdown

GitHub release for Sodium v2.2.0 has been created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants