Add support for SecretManagement and SecretStore providers, enhance configuration data handling, and introduce new utility functions
This commit is contained in:
31
Private/New-ConfigurationDataAesKeyFile.ps1
Normal file
31
Private/New-ConfigurationDataAesKeyFile.ps1
Normal file
@@ -0,0 +1,31 @@
|
||||
function New-ConfigurationDataAesKeyFile {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]
|
||||
$Force
|
||||
)
|
||||
|
||||
if((Test-Path -Path $Path -PathType Leaf) -and (-not $Force)){
|
||||
$Key = [Convert]::FromBase64String((Get-Content -Path $Path -Raw).Trim())
|
||||
if($Key.Length -notin @(16, 24, 32)){
|
||||
throw "Existing key file [$Path] does not contain a valid AES key length."
|
||||
}
|
||||
|
||||
return $Key
|
||||
}
|
||||
|
||||
$Parent = Split-Path -Path $Path -Parent
|
||||
if(-not [string]::IsNullOrWhiteSpace($Parent) -and -not (Test-Path -Path $Parent)){
|
||||
New-Item -Path $Parent -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
$Key = New-Object byte[] 32
|
||||
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($Key)
|
||||
Set-Content -Path $Path -Value ([Convert]::ToBase64String($Key)) -Encoding ASCII
|
||||
return $Key
|
||||
}
|
||||
Reference in New Issue
Block a user