Загрузка данных


mkdir C:\lab -Force; cd C:\lab

$pass = ConvertTo-SecureString "123456" -AsPlainText -Force
Import-PfxCertificate -FilePath C:\lab\cert.pfx -CertStoreLocation Cert:\CurrentUser\My -Password $pass

Unprotect-CmsMessage -Path C:\lab\a.enc | Set-Content C:\lab\a_dec.txt -Encoding UTF8

$c = Get-ChildItem Cert:\CurrentUser\My | Where-Object Subject -eq "CN=LabCert"
$priv = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($c)
$pad = [System.Security.Cryptography.RSAEncryptionPadding]::OaepSHA256
[IO.File]::WriteAllBytes("C:\lab\b_dec.txt", $priv.Decrypt([IO.File]::ReadAllBytes("C:\lab\b.enc"), $pad))

type C:\lab\a_dec.txt
type C:\lab\b_dec.txt