从php脚本解密powershell中使用Rijndael方法创建的文本
有人能帮我用一个php脚本来解密在powershell中使用Rijndael密钥创建的php值吗 下面是我用来创建它的powershell脚本从php脚本解密powershell中使用Rijndael方法创建的文本,php,powershell,encryption,Php,Powershell,Encryption,有人能帮我用一个php脚本来解密在powershell中使用Rijndael密钥创建的php值吗 下面是我用来创建它的powershell脚本 [Reflection.Assembly]::LoadFile('C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll') | out-null $XCADMPass = "CloudyTest" $r = new-Object System.Security.Cryptography
[Reflection.Assembly]::LoadFile('C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll') | out-null
$XCADMPass = "CloudyTest"
$r = new-Object System.Security.Cryptography.RijndaelManaged # use Rijndael symmetric key encryption
$c = $r.CreateEncryptor((1..16), (1..16)) # Set the key and initialisation vector to 128-bytes each of (1..16)
$ms = new-Object IO.MemoryStream
$cs = new-Object Security.Cryptography.CryptoStream $ms,$c,"Write" # Target data stream, transformation, and mode
$sw = new-Object IO.StreamWriter $cs
$sw.Write($XCADMPass) # Write the string through the crypto stream into the memory stream
$sw.Close()
$cs.Close()
$ms.Close()
$r.Clear()
[byte[]]$result = $ms.ToArray() # Byte array from the encrypted memory stream
$encPass = [Convert]::ToBase64String($result)
加密值为yD3/YeGk64JJ2LUI20mo8Q==
我尝试过使用mcrypt_decrypt,但无法找到获取原始文本的正确方法
这就是我尝试过的
$input = "yD3/YeGk64JJ2LUI20mo8Q==";
$key = "12345678910111213141516";
$data = base64_decode($input);
$iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
$decrypted = rtrim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
$key,
substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)),
MCRYPT_MODE_CBC,
$iv
),
"\0"
);
很明显,我在某个地方出了问题,所以我们非常感谢您的帮助。感谢所有在这方面提供帮助的人。我将为遇到类似问题的任何其他人显示最终代码 动力壳
[Reflection.Assembly]::LoadFile('C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll') | out-null
$XCADMPass = "CloudyTest"
$r = new-Object System.Security.Cryptography.RijndaelManaged # use Rijndael symmetric key encryption
$c = $r.CreateEncryptor((1..16), (1..16)) # Set the key and initialisation vector to 128-bytes each of (1..16)
$ms = new-Object IO.MemoryStream
$cs = new-Object Security.Cryptography.CryptoStream $ms,$c,"Write" # Target data stream, transformation, and mode
$sw = new-Object IO.StreamWriter $cs
$sw.Write($XCADMPass) # Write the string through the crypto stream into the memory stream
$sw.Close()
$cs.Close()
$ms.Close()
$r.Clear()
[byte[]]$result = $ms.ToArray() # Byte array from the encrypted memory stream
$encPass = [Convert]::ToBase64String($result)
PHP
PHP端的键错误。正确的密钥应该是
“#1#2#3#4#5#6#7#8#9#10#11#13#14#15#16”
。我将密钥更改为建议的内容,但现在的密钥是long和mcryptwarning@Vesper#
?当然不应该是\x01..\x16
?@MathiasR.Jessen#
似乎语言错误。很抱歉。因此我将密钥更改为\x01..\x16
,这会对警告进行排序,但不会解密为正确的字符串。
$input = "yD3/YeGk64JJ2LUI20mo8Q==";
$iv = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10";
$key = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10";
$data = base64_decode($input);
$decrypted = rtrim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
$key,
$data,
MCRYPT_MODE_CBC,
$iv
),
"\0"
);
echo $decrypted;