Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Rijndael解密逻辑从C#更改为Python_Python_C#_Rijndael_Rijndaelmanaged - Fatal编程技术网

将Rijndael解密逻辑从C#更改为Python

将Rijndael解密逻辑从C#更改为Python,python,c#,rijndael,rijndaelmanaged,Python,C#,Rijndael,Rijndaelmanaged,我有一些已经加密的数据,需要用python解密。C#中的解密逻辑如下所示 使用System.Security.Cryptography; 私有常量字符串Url\u ENCRYPTION\u KEY=“abcd123456”; 私有只读静态字节[]URL\u SALT=Encoding.ASCII.GetBytes(URL\u ENCRYPTION\u KEY.Length.ToString()); 公共静态字符串解密(字符串输入文本){ 试一试{ 如果(!string.IsNullOrEmpty

我有一些已经加密的数据,需要用python解密。C#中的解密逻辑如下所示

使用System.Security.Cryptography;
私有常量字符串Url\u ENCRYPTION\u KEY=“abcd123456”;
私有只读静态字节[]URL\u SALT=Encoding.ASCII.GetBytes(URL\u ENCRYPTION\u KEY.Length.ToString());
公共静态字符串解密(字符串输入文本){
试一试{
如果(!string.IsNullOrEmpty(inputText)){
RijndaelManaged rijndaelCipher=新的RijndaelManaged();
字节[]encryptedData=Convert.FromBase64String(inputText.Replace(“,”+”);
PasswordDeriveBytes secretKey=新的PasswordDeriveBytes(Url\加密\密钥,Url\盐);
使用(ICryptoTransform)解密程序=
rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32),secretKey.GetBytes(16))){
使用(MemoryStream MemoryStream=新的MemoryStream(encryptedData)){
使用(加密流)加密流=
新的加密流(memoryStream、解密程序、CryptoStreamMode.Read)){
字节[]明文=新字节[encryptedData.Length];
int decryptedCount=cryptoStream.Read(明文,0,明文.Length);
返回Encoding.Unicode.GetString(纯文本,0,decryptedCount);
}
}
}
}
}
捕获(例外情况除外){
//clsErrorHandler.LogError(ex);
}
返回输入文本;
}
我已经尝试过像pprp和python的加密之类的LIB,但是解决方案使用了PBKDF2,而这里的C#代码提供了密钥和salt的解密字节作为密钥和IV值。 从我看来,PasswordDeriveBytes函数基本上是一个经过修改的PBKDF1函数, 但我尝试的所有解决方案都失败了,因为某种深奥的原因,这个尺寸与那个尺寸的错误不匹配。 下面是一个我在那里找到的PasswordDeriveBytes的实现,但我不知道如何做类似于
secretKey.GetBytes(32)
和创建解密程序的事情

导入hashlib
从base64导入B64解码
def MS_PasswordDeriveBytes(pstring、salt、hashfunc、iterations、keylen):
如果迭代次数>0:
lasthash=hashlib.sha1(pstring+salt).digest()
迭代次数-=1
其他:
打印(“迭代次数必须大于0”)
#如果迭代次数为1,那么根据我的测试,基本上发生与2相同的事情
#如果迭代次数==0且keylen>len(lasthash):
#打印(“不知道这里发生了什么”)
#返回-1
对于范围内的i(迭代次数-1):
lasthash=hashlib.sha1(lasthash)
bytes=hashlib.sha1(lasthash.digest())
ctrl=1
而len(字节)