File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ function Get-PrivateKey {
2+ [CmdletBinding ()]
3+ param (
4+ [Parameter (Mandatory = $false , Position = 0 )]
5+ [System.Security.Cryptography.RSACryptoServiceProvider ]$cryptoServiceProvider
6+ )
7+
8+ begin {
9+ Write-Verbose " Cmdlet Get-PrivateKey - Begin"
10+ }
11+
12+ process {
13+ Write-Verbose " Cmdlet Get-PrivateKey - Process"
14+ if ($cryptoServiceProvider -eq $null ) {
15+ $cryptoServiceProvider = [System.Security.Cryptography.RSACryptoServiceProvider ]::new(2048 )
16+ }
17+ Get-KeyString $cryptoServiceProvider.ExportParameters ($true )
18+ }
19+
20+ end {
21+ Write-Verbose " Cmdlet Get-PrivateKey - End"
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ function Get-PublicKey {
2+ [CmdletBinding ()]
3+ param (
4+ [Parameter (Mandatory = $false , Position = 0 )]
5+ [System.Security.Cryptography.RSACryptoServiceProvider ]$cryptoServiceProvider
6+ )
7+
8+ begin {
9+ Write-Verbose " Cmdlet Get-PublicKey - Begin"
10+ }
11+
12+ process {
13+ Write-Verbose " Cmdlet Get-PublicKey - Process"
14+ if ($cryptoServiceProvider -eq $null ) {
15+ $cryptoServiceProvider = [System.Security.Cryptography.RSACryptoServiceProvider ]::new(2048 )
16+ }
17+ Get-KeyString $cryptoServiceProvider.ExportParameters ($false )
18+ }
19+
20+ end {
21+ Write-Verbose " Cmdlet Get-PublicKey - End"
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,28 @@ Describe 'Crypto.RSA.Tests' {
99 $keys.public | Should -Not - BeNullOrEmpty
1010 $keys.private | Should -Not - BeNullOrEmpty
1111 }
12+
13+ It " Generates private key - using the same csp" {
14+ $csp = [System.Security.Cryptography.RSACryptoServiceProvider ]::new(2048 )
15+ $keys = New-KeyPair $csp
16+ Get-PrivateKey $csp | Should Be $keys.private
17+ }
18+
19+ It " Generates private key - using different csp" {
20+ $keys = New-KeyPair
21+ Get-PrivateKey | Should Not Be $keys.private
22+ }
23+
24+ It " Generates public key - using the same csp" {
25+ $csp = [System.Security.Cryptography.RSACryptoServiceProvider ]::new(2048 )
26+ $keys = New-KeyPair $csp
27+ Get-PublicKey $csp | Should Be $keys.public
28+ }
29+
30+ It " Generates public key - using different csp" {
31+ $keys = New-KeyPair
32+ Get-PublicKey | Should Not Be $keys.public
33+ }
1234 }
1335
1436 Context " String encryption - happy path" {
You can’t perform that action at this time.
0 commit comments