110,580
社区成员
发帖
与我相关
我的任务
分享
#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;
}
}
;
[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);
}