使用RSA公钥加密 - EncryptWithRsa
函数简介
使用RSA公钥对数据进行加密。
接口名称
EncryptWithRsa
DLL调用
long EncryptWithRsa(long instance, string message, string publicKey, int paddingType);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| message | 字符串 | 要加密的明文。 |
| publicKey | 字符串 | RSA公钥。 |
| paddingType | 整数型 | 填充类型:0-PKCS1;1-OAEP。 |
示例
C++
long instance = CreateCOLAPlugInterFace();
// 生成密钥对
GenerateRSAKey(instance, "C:\\keys\\pub.pem", "C:\\keys\\pri.pem", 0, 2048);
// 读取公钥后加密(PKCS1填充)
long encPtr = EncryptWithRsa(instance, "Hello OLA", publicKeyStr, 0);
char* cipher = GetStringFromPtr(encPtr);
// 对应使用 DecryptWithRsa 解密
long decPtr = DecryptWithRsa(instance, cipher, privateKeyStr, 0);
FreeStringPtr(encPtr);
FreeStringPtr(decPtr);
Python
# 待补充
返回值
成功返回加密后的密文字符串的指针;失败返回0。返回的字符串指针需要调用 FreeStringPtr 接口释放内存。
