.net - 在.Net C++中解密字符串
问题描述
我带着小问题来找你。实际上,我正在尝试制作一个能够在.NET C++ 中解密字符串的函数。这是我的函数代码:
array<Byte>^ chipherbytes;
array<Byte>^ plainbytes2;
array<Byte>^ plainkey;
SymmetricAlgorithm^ desObj;
desObj = Rijndael::Create();
chipherbytes = Encoding::ASCII->GetBytes(dataGridView1->CurrentCell->Value->ToString());
plainkey = Encoding::ASCII->GetBytes("0123456789abcdef");
desObj->Key = plainkey;
desObj->Mode = CipherMode::CBC;
desObj->Padding=PaddingMode::PKCS7;
MemoryStream^ ms1 = gcnew MemoryStream(chipherbytes);
CryptoStream^ cs1 = gcnew CryptoStream(ms1, desObj->CreateDecryptor(), CryptoStreamMode::Read);
cs1->Read(chipherbytes, 0, chipherbytes->Length); //<- in this line is problem
plainbytes2 = ms1->ToArray();
cs1->Close();
ms1->Close();
textBox1->Text = Encoding::ASCII->GetString(plainbytes2);
但是当我开始调试并且稍后我打开此功能时,程序崩溃并且正在通信“System.Security.Cryptography.CryptographicException:补码无效并且无法删除。” 它显示在标记的标签中。有人可以给我建议吗?
编辑:
这是代码的加密部分:
cipherData = textBox6->Text;
plainbytes = Encoding::ASCII->GetBytes(cipherData);
plainkey = Encoding::ASCII->GetBytes("0123456789abcdef");
desObj->Key = plainkey;
//choose other appropriate modes (CBC,CFB,CTS,ECB,OFB)
desObj->Mode = CipherMode::CBC;
desObj->Padding = PaddingMode::PKCS7;
MemoryStream^ ms = gcnew MemoryStream();
CryptoStream^ cs = gcnew CryptoStream(ms,desObj->CreateEncryptor(),CryptoStreamMode::Write);
cs->Write(plainbytes,0,plainbytes->Length);
cs->Close();
chipherbytes = ms->ToArray();
ms->Close();
textBox7->Text = Encoding::ASCII->GetString(chipherbytes);
顺便说一句,我想将加密数据发送到 mysql 数据库,然后从数据库下载并解密。
解决方案
推荐阅读
- visual-studio-code - 即使在安装 ESlint 后,箭头功能也无法在 VS 代码中起作用
- mdriven - 使用 ModelDrivenControllerBase 调用 MDrivenEcoSpaceAndModelForNetStandard 时出现 ESType 错误
- blockchain - 如何调试 Chainlink 作业任务?
- javascript - 如何使用javascript旋转移动相机?
- spring - 为什么我应该在 STOMP send() 方法中使用 JSON.stringify() ?
- javascript - POST 请求生成失败获取
- docker - Phoenix Liveview - 容器外的资产
- reactjs - React:如何引导新页面
- python - 如何使用熊猫将 xlxs 文件中的内容转换为 python 中的列表列表?
- c++ - 构建 C++ 项目时出现错误“NETFX 4.8 Toolswsdl 无法识别为内部或外部命令、可运行程序或批处理文件”