CaiWuXiTong/scripts/wangshang-bank/cookie-protection.ps1
92451 67c85678e6 feat: 接入网商银行每日动账明细 (#831)
Co-authored-by: 92451 <924518135@qq.com>
Co-committed-by: 92451 <924518135@qq.com>
2026-11-02 20:58:42 +08:00

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))