主题
AES加密 - AESEncryptEx
函数简介
AES加密,支持多种加密模式和填充类型。
接口名称
AESEncryptExDLL调用
c
long AESEncryptEx(long instance, string source, string key, string iv, int mode, int paddingType);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| source | 字符串 | 源数据。 |
| key | 字符串 | 密钥。 |
| iv | 字符串 | 初始向量。 |
| mode | 整数型 | 加密模式:0-CBC;1-ECB;2-CFB;3-OFB;4-CTS。 |
| paddingType | 整数型 | 填充类型:0-PKCS7;1-Zeros;2-AnsiX923;3-ISO10126;4-NoPadding。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string cipher = ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);csharp
using OLAPlug;
var ola = new OLAPlugServer();
string cipher = ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
cipher = ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);cpp
var ola = com("OlaPlug.OlaSoft")
ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.AESEncryptEx("hello ola", "1234567890123456", "0000000000000000", 0, 0);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = AESEncryptEx(instance, "hello ola", "1234567890123456", "0000000000000000", 0, 0);
if (ptr != 0) {
char buffer[4096] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long AESEncryptEx(long ola, string source, string key, string iv, int mode, int paddingType);
long instance = CreateCOLAPlugInterFace();
long ptr = AESEncryptEx(instance, "hello ola", "1234567890123456", "0000000000000000", 0, 0);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string cipher = sb.ToString();
}python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.AESEncryptEx(instance, b"hello ola", b"1234567890123456", b"0000000000000000", 0, 0)返回值
| 返回值 | 说明 |
|---|---|
非 0 | 成功,返回 加密后的数据的字符串指针。 |
0 | 失败。 |
