35 lines
936 B
PowerShell
35 lines
936 B
PowerShell
#Requires -Version 5.1
|
|
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateSet('Protect', 'Unprotect')]
|
|
[string] $Action
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
Add-Type -AssemblyName System.Security
|
|
$payload = [Console]::In.ReadToEnd().Trim()
|
|
if ([string]::IsNullOrWhiteSpace($payload)) {
|
|
throw 'Cookie protection input is empty'
|
|
}
|
|
|
|
$bytes = [Convert]::FromBase64String($payload)
|
|
$entropy = [Text.Encoding]::UTF8.GetBytes('CaiWuXiTong.WangshangBank.Cookies.v1')
|
|
if ($Action -eq 'Protect') {
|
|
$output = [Security.Cryptography.ProtectedData]::Protect(
|
|
$bytes,
|
|
$entropy,
|
|
[Security.Cryptography.DataProtectionScope]::CurrentUser
|
|
)
|
|
} else {
|
|
$output = [Security.Cryptography.ProtectedData]::Unprotect(
|
|
$bytes,
|
|
$entropy,
|
|
[Security.Cryptography.DataProtectionScope]::CurrentUser
|
|
)
|
|
}
|
|
|
|
[Console]::Out.Write([Convert]::ToBase64String($output))
|