Skip to content

Repository files navigation

PSCertPatterns

Production cryptographic patterns in PowerShell 7

Overview

PSCertPatterns provides production-grade cryptographic implementations for PowerShell 7, covering AES-GCM symmetric encryption, RSA and ECDSA asymmetric operations, key rotation strategies, algorithm agility patterns, and comprehensive certificate chain validation.

Prerequisites

  • PowerShell 7.4+
  • .NET 8
  • Pester 5.x

Installation

Import-Module ./PSCertPatterns.psm1

Usage

using module ./PSCertPatterns.psm1
# AES-GCM encrypt / decrypt$key= [byte[]]::new(32)
$aesGcm= [AesGcmService]::new($key)
$encrypted=$aesGcm.Encrypt([System.Text.Encoding]::UTF8.GetBytes("Hello, world!"))
$decrypted=$aesGcm.Decrypt($encrypted)
$aesGcm.Dispose()
# PBKDF2 key derivation$salt= [SaltGenerator]::Generate(32)
$derivedKey= [Pbkdf2KeyDerivation]::DeriveKey("password",$salt,32)
# AES-CBC + HMAC Encrypt-then-MAC$encKey= [byte[]]::new(32)
$macKey= [byte[]]::new(32)
$aesCbc= [AesCbcService]::new($encKey,$macKey)
$package=$aesCbc.Encrypt([System.Text.Encoding]::UTF8.GetBytes("Hello, world!"))
$decrypted=$aesCbc.Decrypt($package)
$aesCbc.Dispose()
# RSA encrypt / decrypt (OAEP SHA-256)$rsaEnc= [RsaEncryptionService]::new(2048)
$encrypted=$rsaEnc.Encrypt([System.Text.Encoding]::UTF8.GetBytes("Hello, world!"))
$decrypted=$rsaEnc.Decrypt($encrypted)
$rsaEnc.Dispose()
# RSA sign / verify (PSS SHA-256)$rsaSign= [RsaSigningService]::new(2048)
$data= [System.Text.Encoding]::UTF8.GetBytes("message to sign")
$signature=$rsaSign.Sign($data)
$valid=$rsaSign.Verify($data,$signature)
$rsaSign.Dispose()

Test Suite

Invoke-Pester-Path './tests/*.Tests.ps1'-Output Detailed

254 Pester tests covering all completed slices.

SliceFileClassesTests
1src/01_AesGcm.ps1AesGcmService15
2src/02_KeyDerivation.ps1Pbkdf2KeyDerivation, SaltGenerator14
3src/03_NonceManagement.ps1RandomNonceGenerator, CounterNonceGenerator17
4src/04_HmacCbc.ps1AesCbcService, HmacService27
5src/05_Rsa.ps1RsaEncryptionService, RsaSigningService30
6src/06_Ecdsa.ps1EcdsaSigningService20
7src/07_CertChain.ps1CertificateValidator, InMemoryPki18
8src/08_KeyRotation.ps1RotatingKeyManager, EncryptedPackage21
9src/09_AlgorithmAgility.ps1CipherProfile, AlgorithmRegistry22
10src/10_ReplayProtection.ps1NonceReplayGuard20
Atests/00_Adversarial.Tests.ps1(boundary/adversarial)50

Adversary Tool (Experimental)

The adversary/ folder contains an experimental adversarial battery engine for validating cryptographic pattern implementations against documented behavioral thresholds. It is scoped to PSCertPatterns and is not a general-purpose security testing framework.

See adversary/README.md for full documentation, supported contracts, usage, and the disclaimer you should read before running it.

# Quick start. ./adversary/Invoke-AdversaryBattery.ps1$key= [byte[]]::new(32)
[System.Security.Cryptography.RandomNumberGenerator]::Fill($key)
$svc= [AesGcmService]::new($key)
Invoke-AdversaryBattery-Target $svc-Contract EncryptDecrypt

License

MIT License — see LICENSE for details.


██████╗██╗ ██╗ ██████╗ ██╗ ██╗██╗███╗ ██╗
██╔════╝╚██╗ ██╔╝██╔════╝ ██║ ██║██║████╗ ██║
██║ ╚████╔╝ ██║ ███╗██║ ██║██║██╔██╗ ██║
██║ ╚██╔╝ ██║ ██║██║ ██║██║██║╚██╗██║
╚██████╗ ██║ ╚██████╔╝╚██████╔╝██║██║ ╚████║
╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝
drop-in tools for developers · cyguin.com

About

Production cryptographic patterns in PowerShell 7 — AES-GCM, RSA, ECDSA, key rotation, algorithm agility, and certificate chain validation. 254 Pester tests. MIT license.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages