File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Clear-Host
2+ Import-Module - Name Pester - Force
3+ Import-Module .\Crypto.RSA\Crypto.RSA.psm1 - Force
4+
5+ Describe ' Crypto.RSA.Tests' {
6+ Context " Keys generation" {
7+ It " Generates public and private keys" {
8+ $keys = New-KeyPair
9+ $keys.public | Should -Not - BeNullOrEmpty
10+ $keys.private | Should -Not - BeNullOrEmpty
11+ }
12+ }
13+
14+ Context " String encryption - happy path" {
15+ $keys = New-KeyPair
16+ $plain = " Crypto.RSA"
17+
18+ $encryptedText = Protect-String $plain $keys.public
19+ $decryptedText = Unprotect-String $encryptedText $keys.private
20+
21+ It " Encrypted text is NOT the same as plain" {
22+ $encryptedText | Should -Not - Be $plain
23+ }
24+ It " Decrypted text is the same as plain" {
25+ $decryptedText | Should - Be $plain
26+ }
27+ }
28+
29+ Context " String encryption - incorrect private key" {
30+ $keys = New-KeyPair
31+ $incorrect_keys = New-KeyPair
32+ $plain = " Crypto.RSA"
33+ $encryptedText = Protect-String $plain $keys.public
34+
35+ It " Decrypted with valid key works" {
36+ Unprotect-String $encryptedText $keys.private | Should - Be $plain
37+ }
38+
39+ It " Decrypted with invalid key throws an exception" {
40+ { Unprotect-String $encryptedText $incorrect_keys.private } | Should Throw " Cryptography_OAEPDecoding"
41+ }
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments