主题
使用RSA私钥解密 - DecryptWithRsa
函数简介
使用RSA私钥对加密的密文进行解密。
接口名称
DecryptWithRsaDLL调用
c
long DecryptWithRsa(long instance, string cipher, string privateKey, int paddingType);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| cipher | 字符串 | 要解密的密文。 |
| privateKey | 字符串 | RSA私钥。 |
| paddingType | 整数型 | 填充类型:0-PKCS1;1-OAEP。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string cipher = ola.EncryptWithRsa("hello ola", publicKey, 0);
std::string plain = ola.DecryptWithRsa(cipher, privateKey, 0);csharp
using OLAPlug;
var ola = new OLAPlugServer();
string cipher = ola.EncryptWithRsa("hello ola", publicKey, 0);
string plain = ola.DecryptWithRsa(cipher, privateKey, 0);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
cipher = ola.EncryptWithRsa("hello ola", public_key, 0)
plain = ola.DecryptWithRsa(cipher, private_key, 0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.DecryptWithRsa(cipher, privateKey, 0);cpp
var ola = com("OlaPlug.OlaSoft")
ola.DecryptWithRsa(cipher, privateKey, 0);vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.DecryptWithRsa(cipher, privateKey, 0);text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.DecryptWithRsa(cipher, privateKey, 0);aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.DecryptWithRsa(cipher, privateKey, 0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.DecryptWithRsa(cipher, privateKey, 0);cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.DecryptWithRsa(cipher, privateKey, 0);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = DecryptWithRsa(instance, cipher, privateKey, 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 DecryptWithRsa(long ola, string cipher, string privateKey, int paddingType);
long instance = CreateCOLAPlugInterFace();
long ptr = DecryptWithRsa(instance, cipher, privateKey, 0);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string plain = 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.DecryptWithRsa(instance, cipher, private_key, 0)返回值
| 返回值 | 说明 |
|---|---|
非 0 | 成功,返回 解密后的明文字符串的指针。 |
0 | 失败。 |
