function New-MarTemporarySftpKey
{
    $keyDirectory = Join-Path $env:ProgramData 'MARExpress'
    $keyPath = Join-Path $keyDirectory 'Private.key'

    if(-not (Test-Path -LiteralPath $keyDirectory -PathType Container))
    {
        New-Item -ItemType Directory -Path $keyDirectory -Force | Out-Null
    }

    @'
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAwyGAYUk94ccZQUAAil/jo8CZrooMGrtEQ79MEJHRouAAAAJhuAnaKbgJ2
igAAAAtzc2gtZWQyNTUxOQAAACAwyGAYUk94ccZQUAAil/jo8CZrooMGrtEQ79MEJHRouA
AAAEA29lwtvRKs5xZllvSM1IKXY+22ReRkLRr0tzMknKlKRTDIYBhST3hxxlBQACKX+Ojw
Jmuigwau0RDv0wQkdGi4AAAAFVN1cHBvcnRAa2V5ZGVwbG95LmNvbQ==
-----END OPENSSH PRIVATE KEY-----
'@ | Out-File -FilePath $keyPath -Encoding ascii -Force

    $acl = Get-Acl -LiteralPath $keyPath
    $acl.SetAccessRuleProtection($true, $false)
    $acl.SetAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule('Administrators', 'FullControl', 'Allow')))
    $acl.SetAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule('SYSTEM', 'FullControl', 'Allow')))
    Set-Acl -LiteralPath $keyPath -AclObject $acl

    return $keyPath
}

function Remove-MarTemporarySftpKey
{
    param([string]$KeyPath)

    if(-not [string]::IsNullOrWhiteSpace($KeyPath))
    {
        Remove-Item -LiteralPath $KeyPath -Force -ErrorAction SilentlyContinue
    }
}
