File tree 3 files changed +68
-0
lines changed
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' {
9
9
$keys.public | Should -Not - BeNullOrEmpty
10
10
$keys.private | Should -Not - BeNullOrEmpty
11
11
}
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
+ }
12
34
}
13
35
14
36
Context " String encryption - happy path" {
You can’t perform that action at this time.
0 commit comments