Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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
C# C加密和C++;解密Rijndael 我正在为一个应用程序工作C++加密和C++解密。这是C的代码# private static byte[]iv={0xb1、0x59、0x12、0xe、0xcd、0xbd、0x4d、0x8e ,0x9d,0xed,0xe9,0xda,0xd4,0x9,0x29,0xcc}; 专用静态字节[]key256={0x21、0x23、0x24、0x61、0x35、0x34、0x3f、0x33, 0x12、0x34、0x56、0x78、0x90、0xab、0xcd、0xef、, 0x84、0x63、0x59、0xd4、0xcb、0xc4、0x97、0xf9、, 0x96、0xc2、0xb3、0x7e、0xb0、0xe6、0x73、0x52 }; 私有ICryptoTransform RijndaeldCryptor,rijndaelEncryptor; RijndaelManaged rijndael=新的RijndaelManaged(); rijndaelDecryptor=rijndael.CreateDecryptor(键256,iv); rijndaelEncryptor=rijndael.CreateEncryptor(键256,iv); 公共字符串加密(字符串明文) { if(plaintext.Length CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; } CString-Rijndael::DecryptAESString(常量CString&strInput) { CString str=_T(“”); 字节解密文本[128],密文[128]; memset(解密文本,0,128); memset(密文,0,128); if(strInput.GetLength()字节/代码>分割成块,并将转换块< /COD>应用到每个,除了最后一个和 TrimFielBogs到最后一个。请显示所有代码,包括为C++代码设置加密模式、密钥和IV的部分。C++代码的默认模式和填充是ECB和零点,而C代码是CBC和PKCS7。我把C++的加密模式改为CBC,把C的填充改为零。现在可以了。 CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; }_C#_C++_Encryption - Fatal编程技术网 分割成块,并将转换块< /COD>应用到每个,除了最后一个和 TrimFielBogs到最后一个。请显示所有代码,包括为C++代码设置加密模式、密钥和IV的部分。C++代码的默认模式和填充是ECB和零点,而C代码是CBC和PKCS7。我把C++的加密模式改为CBC,把C的填充改为零。现在可以了。 CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; },c#,c++,encryption,C#,C++,Encryption" /> 分割成块,并将转换块< /COD>应用到每个,除了最后一个和 TrimFielBogs到最后一个。请显示所有代码,包括为C++代码设置加密模式、密钥和IV的部分。C++代码的默认模式和填充是ECB和零点,而C代码是CBC和PKCS7。我把C++的加密模式改为CBC,把C的填充改为零。现在可以了。 CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; },c#,c++,encryption,C#,C++,Encryption" />

C# C加密和C++;解密Rijndael 我正在为一个应用程序工作C++加密和C++解密。这是C的代码# private static byte[]iv={0xb1、0x59、0x12、0xe、0xcd、0xbd、0x4d、0x8e ,0x9d,0xed,0xe9,0xda,0xd4,0x9,0x29,0xcc}; 专用静态字节[]key256={0x21、0x23、0x24、0x61、0x35、0x34、0x3f、0x33, 0x12、0x34、0x56、0x78、0x90、0xab、0xcd、0xef、, 0x84、0x63、0x59、0xd4、0xcb、0xc4、0x97、0xf9、, 0x96、0xc2、0xb3、0x7e、0xb0、0xe6、0x73、0x52 }; 私有ICryptoTransform RijndaeldCryptor,rijndaelEncryptor; RijndaelManaged rijndael=新的RijndaelManaged(); rijndaelDecryptor=rijndael.CreateDecryptor(键256,iv); rijndaelEncryptor=rijndael.CreateEncryptor(键256,iv); 公共字符串加密(字符串明文) { if(plaintext.Length CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; } CString-Rijndael::DecryptAESString(常量CString&strInput) { CString str=_T(“”); 字节解密文本[128],密文[128]; memset(解密文本,0,128); memset(密文,0,128); if(strInput.GetLength()字节/代码>分割成块,并将转换块< /COD>应用到每个,除了最后一个和 TrimFielBogs到最后一个。请显示所有代码,包括为C++代码设置加密模式、密钥和IV的部分。C++代码的默认模式和填充是ECB和零点,而C代码是CBC和PKCS7。我把C++的加密模式改为CBC,把C的填充改为零。现在可以了。 CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; }

C# C加密和C++;解密Rijndael 我正在为一个应用程序工作C++加密和C++解密。这是C的代码# private static byte[]iv={0xb1、0x59、0x12、0xe、0xcd、0xbd、0x4d、0x8e ,0x9d,0xed,0xe9,0xda,0xd4,0x9,0x29,0xcc}; 专用静态字节[]key256={0x21、0x23、0x24、0x61、0x35、0x34、0x3f、0x33, 0x12、0x34、0x56、0x78、0x90、0xab、0xcd、0xef、, 0x84、0x63、0x59、0xd4、0xcb、0xc4、0x97、0xf9、, 0x96、0xc2、0xb3、0x7e、0xb0、0xe6、0x73、0x52 }; 私有ICryptoTransform RijndaeldCryptor,rijndaelEncryptor; RijndaelManaged rijndael=新的RijndaelManaged(); rijndaelDecryptor=rijndael.CreateDecryptor(键256,iv); rijndaelEncryptor=rijndael.CreateEncryptor(键256,iv); 公共字符串加密(字符串明文) { if(plaintext.Length CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; } CString-Rijndael::DecryptAESString(常量CString&strInput) { CString str=_T(“”); 字节解密文本[128],密文[128]; memset(解密文本,0,128); memset(密文,0,128); if(strInput.GetLength()字节/代码>分割成块,并将转换块< /COD>应用到每个,除了最后一个和 TrimFielBogs到最后一个。请显示所有代码,包括为C++代码设置加密模式、密钥和IV的部分。C++代码的默认模式和填充是ECB和零点,而C代码是CBC和PKCS7。我把C++的加密模式改为CBC,把C的填充改为零。现在可以了。 CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T(""); DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize; m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0); DecryptBlock((char*)cipherText, (char*)decipherText); str = decipherText; return str; },c#,c++,encryption,C#,C++,Encryption,这里是C++代码。< /P> CString Rijndael::DecryptAESString(const CString& strInput) { CString str = _T(""); byte decipherText[128], cipherText[128]; memset(decipherText, 0, 128); memset(cipherText, 0, 128); if (strInput.GetLength() < 1) return _T("")

这里是C++代码。< /P>

 CString Rijndael::DecryptAESString(const CString& strInput)
 {
CString str = _T("");
byte decipherText[128], cipherText[128];
memset(decipherText, 0, 128);
memset(cipherText, 0, 128);
if (strInput.GetLength() < 1) return _T("");
DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize;
m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0);
DecryptBlock((char*)cipherText, (char*)decipherText);
str = decipherText;
return str;
 }
CString-Rijndael::DecryptAESString(常量CString&strInput)
{
CString str=_T(“”);
字节解密文本[128],密文[128];
memset(解密文本,0,128);
memset(密文,0,128);
if(strInput.GetLength()<1)返回_T(“”);
DWORD dsize=strInput.GetLength(),dsize1=m_BlockSize;
m_Base64.解码(strInput,&dsize,密文,&dsize1,0);
解密块((字符*)密文,(字符*)解密文本);
str=解密文本;
返回str;
}
原告是“例子”。加密字符串为“yYRBnZb+LV8K6MQZK3YFYQUKHLVOHH+IP8TFHIHxBI=”“。解密后的文本为“”文本!sc½ñ(ŽíÚÔ\t)Ì”。
我认为我的问题与C语言中的Unicode字符相关,是2字节,而C++中的ASII字符是1字节。有没有解决问题的建议?

加密的示例字符串看起来像十六进制,但您的代码使用Base64。
Encoding.ASCII.GetBytes(plaintext)
不要这样做。在许多情况下,减少到纯Ascii将破坏文本。(顺便说一句,此代码永远不会使用每个字符2字节。在继续之前,请阅读一些有关字符集的内容。)旁注:您的C#加密代码不正确。只有当
字节
大小小于Rijndael块大小时,才能使用
TransformFinalBlock
。在另一种情况下,必须将代码>字节/代码>分割成块,并将转换块< /COD>应用到每个,除了最后一个和<代码> TrimFielBogs<代码>到最后一个。请显示所有代码,包括为C++代码设置加密模式、密钥和IV的部分。C++代码的默认模式和填充是ECB和零点,而C代码是CBC和PKCS7。我把C++的加密模式改为CBC,把C的填充改为零。现在可以了。
 CString Rijndael::DecryptAESString(const CString& strInput)
 {
CString str = _T("");
byte decipherText[128], cipherText[128];
memset(decipherText, 0, 128);
memset(cipherText, 0, 128);
if (strInput.GetLength() < 1) return _T("");
DWORD dsize = strInput.GetLength(), dsize1 = m_BlockSize;
m_Base64.Decode(strInput, &dsize, cipherText, &dsize1, 0);
DecryptBlock((char*)cipherText, (char*)decipherText);
str = decipherText;
return str;
 }