使用 aes 密钥解密安全字符串

Decrypting secure string with aes key

所以我得到了一个密钥和一个哈希值,可以用 PowerShell 解密。

key: (165, 49, 50, 151, 4, 58, 80, 217, 250, 19, 249, 150, 185, 102, 202, 113)

哈希:

76492d1116743f0423413b16050a5345MgB8AEsAVQBkAGkAWQBQAGYAcgA2ADQASwBCAGQ
AcwBkAFEATQByAFQATABqAFEAPQA9AHwAOQBkAGQAYQA2AGQAYgA4ADQAZQBmAGUAMgBiADQ
ANgA1ADkANAA5AGYAMQBlADIAYgA5ADIAMQBmADUANgA0ADgANgBiADYANwBmAGMANgBjADAA
ZgA5AGUAZQAxAGQANgA3ADUANwA3ADUAZgA1AGYAOABlADcAOQA0AGMAOQA4ADMAZgBmADQ
AMQBkADcAYgAyADkAZQBhADEANwA2AGEAMQBhADMAZQBiADEAOQBkAGMANABiAGIANQBhAGM
AOQA0ADQAMwBhADAAZQAzAGQAZQAwADIANwA2ADUANwAzADcAMABhAGMAMwAxAGYAYwBjA
DYANAA5ADYAZgBlAGQANAA3ADIAMAA2AGUAOQA0ADEAMQA2ADEAYgA2ADMAYgAwADUANQA1A
GQAYQBiADQAOABkAGMANQAyADUAZABkADIANQA5AGQANQA3ADIANgA4ADUAYQA3ADcAMgAxAD
AAOQA2AGUAYQA4ADUAZQAyADgAZABhADMANABlADkANwA0ADIAZQBiADMAMwAzADMAMwAwA
DIAZAA4ADIAYgAwADkAZgBjADUAMgA4AGQANQBkADUAOQA0ADgAMwA4ADEAYgBmAGIAMwBjAGU
AYQAyADUAZgA3ADgAOQA0AGUAZABiAGMAYgBkADcANQAyADQAOQA0ADkANwAxADgAOQAxAGMA
ZAA5ADcAMQA2AGQAOABjAGQAOQAyAGIANQA0AGUAZgAzADcANwA0ADkAOQAxAGIANQA2AGUANw
AyADIAMAA5ADcAOQA3ADIANwAyADAAZgAyAGUAMgA2AGQAMwA1ADMAMAA1AGUAYwAxADcAYw
A2AGQAMwA2AGQAZQBjADgANwAyADYAYwBkADgANQA5AGYANwAwAGUAMQA3AGUANwBkADIAMQ
A4ADgANAA2ADIANAAwAGIANAA5ADgAMwBiADMAOAA1ADUAYgBiAGUAMABhAGIANgAxAGEAMwB
mADYAYQA5ADUANQBmAGUAZQAyADAAZQBhADAAZQAxADUAOAAxAGIAZQA1ADMAMAA5AGUAYQ
BiADkANwAwAGQAMQBmAGQAYgAxAGIANQA0ADAAYwAwADMAOQA5ADcANQA1ADcAOABjADUANg
AyADAAMAA2ADEAZAAyAGQAYgA0ADYAZAA2AGUAOABhADUANQA4ADgAYQA0AGMAZgAwADQANwB
lAGMAZABiAGQAYgBjADQANwA1AGQAYQA2ADQAYgA4ADcAMAAzADIAMgBhADIAZgA1ADAANgA4AGU
AYwBlADgAMgA4AGEAMwAzAGYAMAAzADkANQBlADkAMgBkADIAMgA1ADAAOAA4AGIAOQA3AGUAYg
AzADIAZQA3ADMAMQA4AA==

我的代码:

$Key = (165, 49, 50, 151, 4, 58, 80, 217, 250, 19, 249, 150, 185, 102, 202, 113)
ConvertFrom-SecureString (ConvertTo-SecureString             
"abovehash" -AsPlainText -Force) -Key $Key

我的理论是,它已经是一个安全字符串,但要将其转换为纯文本,我需要转换为和转换为转换它。我使用了一个完美解码的网站 https://www.wietzebeukema.nl/powershell-securestring-decoder/#

我再次对散列进行了重新散列。

我知道如何制作我自己的安全密钥并对其进行解密,但是如果您获得了哈希和密钥,您将如何解密哈希。

我记得我在 4 或 5 年前尝试这样做以在其中存储随机的东西。我发现由于某种原因 ConvertFrom-SecureString 从未起作用。经过一番研究后,我发现使用 System.Runtime.InteropServices.Marshal SecureStringtoBTSR 从 SecureString 转换为 BTSR,然后使用 PtrToStringAuto 将正确解密。我会尝试找到原因并 post 它。但这应该有效并为您提供您想要的信息:

$Key = (165, 49, 50, 151, 4, 58, 80, 217, 250, 19, 249, 150, 185, 102, 202, 113)
$hash = "76492d1116743f0423413b16050a5345MgB8AEsAVQBkAGkAWQBQAGYAcgA2ADQASwBCAGQAcwBkAFEATQByAFQATABqAFEAPQA9AHwAOQBkAGQAYQA2AGQAYgA4ADQAZQBmAGUAMgBiADQANgA1ADkANAA5AGYAMQBlADIAYgA5ADIAMQBmADUANgA0ADgANgBiADYANwBmAGMANgBjADAAZgA5AGUAZQAxAGQANgA3ADUANwA3ADUAZgA1AGYAOABlADcAOQA0AGMAOQA4ADMAZgBmADQAMQBkADcAYgAyADkAZQBhADEANwA2AGEAMQBhADMAZQBiADEAOQBkAGMANABiAGIANQBhAGMAOQA0ADQAMwBhADAAZQAzAGQAZQAwADIANwA2ADUANwAzADcAMABhAGMAMwAxAGYAYwBjADYANAA5ADYAZgBlAGQANAA3ADIAMAA2AGUAOQA0ADEAMQA2ADEAYgA2ADMAYgAwADUANQA1AGQAYQBiADQAOABkAGMANQAyADUAZABkADIANQA5AGQANQA3ADIANgA4ADUAYQA3ADcAMgAxADAAOQA2AGUAYQA4ADUAZQAyADgAZABhADMANABlADkANwA0ADIAZQBiADMAMwAzADMAMwAwADIAZAA4ADIAYgAwADkAZgBjADUAMgA4AGQANQBkADUAOQA0ADgAMwA4ADEAYgBmAGIAMwBjAGUAYQAyADUAZgA3ADgAOQA0AGUAZABiAGMAYgBkADcANQAyADQAOQA0ADkANwAxADgAOQAxAGMAZAA5ADcAMQA2AGQAOABjAGQAOQAyAGIANQA0AGUAZgAzADcANwA0ADkAOQAxAGIANQA2AGUANwAyADIAMAA5ADcAOQA3ADIANwAyADAAZgAyAGUAMgA2AGQAMwA1ADMAMAA1AGUAYwAxADcAYwA2AGQAMwA2AGQAZQBjADgANwAyADYAYwBkADgANQA5AGYANwAwAGUAMQA3AGUANwBkADIAMQA4ADgANAA2ADIANAAwAGIANAA5ADgAMwBiADMAOAA1ADUAYgBiAGUAMABhAGIANgAxAGEAMwBmADYAYQA5ADUANQBmAGUAZQAyADAAZQBhADAAZQAxADUAOAAxAGIAZQA1ADMAMAA5AGUAYQBiADkANwAwAGQAMQBmAGQAYgAxAGIANQA0ADAAYwAwADMAOQA5ADcANQA1ADcAOABjADUANgAyADAAMAA2ADEAZAAyAGQAYgA0ADYAZAA2AGUAOABhADUANQA4ADgAYQA0AGMAZgAwADQANwBlAGMAZABiAGQAYgBjADQANwA1AGQAYQA2ADQAYgA4ADcAMAAzADIAMgBhADIAZgA1ADAANgA4AGUAYwBlADgAMgA4AGEAMwAzAGYAMAAzADkANQBlADkAMgBkADIAMgA1ADAAOAA4AGIAOQA3AGUAYgAzADIAZQA3ADMAMQA4AA=="
$Secured = $hash | ConvertTo-SecureString -key $key

$BTSR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Secured)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BTSR)

当然,以纯粹的 Microsoft 方式,解释文章不再像以前那样存在。一旦有了上下文推理,我就会更新。

更新

这是一个 SO 答案,给出了一些上下文: