Skip to content

Commit 5ecd58d

Browse files
Restore libsodium attribution, prerequisites, and usage showcase
1 parent f76cbbd commit 5ecd58d

1 file changed

Lines changed: 65 additions & 5 deletions

File tree

README.md

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# Sodium
22

3-
Sodium is a PowerShell module for handling libsodium-based encryption and decryption.
3+
Sodium is a PowerShell module that provides direct bindings to the [`libsodium`](https://github.com/jedisct1/libsodium)
4+
cryptographic library, enabling libsodium-based encryption and decryption directly from PowerShell.
5+
6+
This module was initially created to serve the needs of the [GitHub PowerShell module](https://github.com/PSModule/GitHub).
7+
GitHub's method for creating or updating
8+
[secrets via the REST API](https://docs.github.com/en/rest/guides/encrypting-secrets-for-the-rest-api?apiVersion=2022-11-28#example-encrypting-a-secret-using-c)
9+
requires that secrets be encrypted using libsodium.
10+
11+
## Prerequisites
12+
13+
This module relies on the following:
14+
15+
- The [libsodium](https://github.com/jedisct1/libsodium) library for cryptographic operations.
16+
- Cross-platform PowerShell 7.6 or later.
17+
18+
On Windows, the module also requires the Microsoft Visual C++ Redistributable for Visual Studio 2015 or later.
419

520
## Installation
621

@@ -11,7 +26,50 @@ Install-PSResource -Name Sodium
1126
Import-Module -Name Sodium
1227
```
1328

14-
On Windows, the module requires the Microsoft Visual C++ Redistributable for Visual Studio 2015 or later.
29+
## Usage
30+
31+
### Example: Generate a new key pair
32+
33+
Create a new cryptographic key pair. The keys are returned as an object with `PublicKey` and `PrivateKey`
34+
properties, encoded in base64.
35+
36+
```powershell
37+
New-SodiumKeyPair
38+
39+
PublicKey PrivateKey
40+
--------- ----------
41+
9fv51aqi00MYN4UR7Ew/DLXMS9t1NapLs7yyo+vegz4= MiJAFUZxZ1UCbQTwKfH7HY6AhIFYQlnok5fBD2K+y/g=
42+
```
43+
44+
### Example: Encrypt a message with a public key
45+
46+
Encrypt a message using a recipient's public key with
47+
[sealed boxes](https://doc.libsodium.org/public-key_cryptography/sealed_boxes).
48+
49+
```powershell
50+
$params = @{
51+
Message = 'mymessage'
52+
PublicKey = '9fv51aqi00MYN4UR7Ew/DLXMS9t1NapLs7yyo+vegz4='
53+
}
54+
ConvertTo-SodiumSealedBox @params
55+
56+
905j4S/JyP9XBBmOIdHSOXiDu7fUtZo9TFIMnAfBMESgcVBwttLnEyxJn4xPEX5OMKQ+Bc4P6Hg=
57+
```
58+
59+
### Example: Decrypt a sealed box
60+
61+
Decrypt a sealed box back to the original message. Both the public and private keys are required.
62+
63+
```powershell
64+
$params = @{
65+
SealedBox = '905j4S/JyP9XBBmOIdHSOXiDu7fUtZo9TFIMnAfBMESgcVBwttLnEyxJn4xPEX5OMKQ+Bc4P6Hg='
66+
PublicKey = '9fv51aqi00MYN4UR7Ew/DLXMS9t1NapLs7yyo+vegz4='
67+
PrivateKey = 'MiJAFUZxZ1UCbQTwKfH7HY6AhIFYQlnok5fBD2K+y/g=' #gitleaks:allow
68+
}
69+
ConvertFrom-SodiumSealedBox @params
70+
71+
mymessage
72+
```
1573

1674
## Documentation
1775

@@ -21,9 +79,11 @@ Use PowerShell help and command discovery for module details:
2179

2280
```powershell
2381
Get-Command -Module Sodium
24-
Get-Help ConvertTo-SodiumSealedBox -Examples
82+
Get-Help -Name ConvertTo-SodiumSealedBox -Examples
2583
```
2684

27-
## Contributing
85+
## Acknowledgements
86+
87+
This module would not be possible without the following resources:
2888

29-
Issues and pull requests are welcome. Please use the repository issue tracker to report bugs, request features, or discuss improvements.
89+
- **libsodium** | [Docs](https://doc.libsodium.org/) | [GitHub](https://github.com/jedisct1/libsodium)

0 commit comments

Comments
 (0)