C#调用C++的AES加密库为什么显示不对呢

APPLYI APPLYI 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
C++ dll库代码如下

#include "AES.h"
#include<string.h>
#define AES_API __declspec(dllexport)
class AES {

AES_API unsigned char* Encrypt(unsigned char* str)
{
aes256_context ctx;
unsigned char key[32] = "123yr9012res012345678901";
unsigned char* buf = new unsigned char[256];
buf = str;
aes256_init(&ctx, key);
aes256_encrypt_ecb(&ctx, buf);
for (int i = 0; i < 256; i++)
printf("%c", buf[i]);
return buf;
}

AES_API unsigned char* Decrypt(unsigned char* str)
{
aes256_context ctx;
unsigned char key[32] = "123yr9012res012345678901";
unsigned char* buf = new unsigned char[256];
buf = str;
aes256_init(&ctx, key);
aes256_decrypt_ecb(&ctx, buf);
aes256_done(&ctx);
for (int i = 0; i < 256; i++)
printf("%c", buf[i]);
return buf;
}
}
;


C#调用

[DllImport("AES.dll",EntryPoint = "Encrypt")]
extern static IntPtr Encrypt(byte[] str);
static void Main(string[] args)
{
string str = "123456";
byte[] bx = new byte[256];
bx = Encoding.Default.GetBytes(str);
Encrypt(bx);
}


显示的结果与C++软件测试的不一样,而且数组传过去后再输出出来123456后面又多了一些字符,求告知为什么?新手不太懂
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
APPLYI
C# 111,128 成员 642,536 内容