1+ function New-AesManagedObject {
2+ [CmdletBinding ()]
3+ param (
4+ [Parameter (Mandatory = $false , Position = 0 )]
5+ $Key ,
6+ [Parameter (Mandatory = $false , Position = 1 )]
7+ $InitializationVector ,
8+ [Parameter (Mandatory = $false , Position = 2 )]
9+ [System.Security.Cryptography.CipherMode ]$Mode = [System.Security.Cryptography.CipherMode ]::CBC,
10+ [Parameter (Mandatory = $false , Position = 3 )]
11+ [System.Security.Cryptography.PaddingMode ]$Padding = [System.Security.Cryptography.PaddingMode ]::Zeros,
12+ [Parameter (Mandatory = $false , Position = 4 )]
13+ [int ]$BlockSize = 128 ,
14+ [Parameter (Mandatory = $false , Position = 5 )]
15+ [int ]$KeySize = 256
16+ )
17+
18+ begin {
19+ Write-Verbose " Cmdlet New-AesManagedObject - Begin"
20+ }
21+
22+ process {
23+ Write-Verbose " Cmdlet New-AesManagedObject - Process"
24+ $aesManaged = New-Object " System.Security.Cryptography.AesManaged"
25+ $aesManaged.Mode = $Mode
26+ $aesManaged.Padding = $Padding
27+ $aesManaged.BlockSize = $BlockSize
28+ $aesManaged.KeySize = $KeySize
29+ if ($InitializationVector ) {
30+ if ($InitializationVector.getType ().Name -eq " String" ) {
31+ $aesManaged.IV = [System.Convert ]::FromBase64String($InitializationVector )
32+ }
33+ else {
34+ $aesManaged.IV = $InitializationVector
35+ }
36+ }
37+ if ($Key ) {
38+ if ($Key.getType ().Name -eq " String" ) {
39+ $aesManaged.Key = [System.Convert ]::FromBase64String($Key )
40+ }
41+ else {
42+ $aesManaged.Key = $Key
43+ }
44+ }
45+ $aesManaged
46+ }
47+
48+ end {
49+ Write-Verbose " Cmdlet New-AesManagedObject - End"
50+ }
51+ }
0 commit comments