Skip to content

ConvertTo-SodiumSealedBox rejects empty messages due to mandatory parameter #75

Description

Problem

ConvertTo-SodiumSealedBox uses [Parameter(Mandatory)] for the -Message parameter, which causes PowerShell to reject empty strings ('') in addition to $null. This means users cannot encrypt an empty plaintext value through the public command, even though the underlying C# wrapper SealBase64 only rejects $null and would otherwise handle an empty string correctly.

Reproduction

$keyPair = New-SodiumKeyPair
ConvertTo-SodiumSealedBox -Message '' -PublicKey $keyPair.PublicKey

Actual: Cannot bind argument to parameter 'Message' because it is an empty string.

Expected: The command should return a valid base64-encoded sealed box representing an empty plaintext, consistent with libsodium's crypto_box_seal behavior.

Suggested fix

Add [AllowEmptyString()] to the -Message parameter so empty strings are accepted and passed through to the C# layer.

Related code

  • src/functions/public/ConvertTo-SodiumSealedBox.ps1
  • PSModule/Sodium/Sodium.cs (SealBase64 method)

Notes

This came up while expanding test coverage. A test for empty-message round-trips was attempted but had to be changed to verify the current rejection behavior instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions