主题
转换RSA私钥 - ConvertRSAPrivateKey
函数简介
将RSA私钥从一种格式转换为另一种格式。
接口名称
ConvertRSAPrivateKeyDLL调用
c
long ConvertRSAPrivateKey(long instance, string privateKey, int inputType, int outputType);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| privateKey | 字符串 | 要转换的私钥。 |
| inputType | 整数型 | 输入类型:0-pem格式;1-xml格式;2-PKCS1格式。 |
| outputType | 整数型 | 输出类型:0-pem格式;1-xml格式;2-PKCS1格式。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// privateKey 为 PEM/XML/PKCS1 格式私钥字符串
std::string converted = ola.ConvertRSAPrivateKey(privateKey, 0, 0);csharp
using OLAPlug;
var ola = new OLAPlugServer();
string converted = ola.ConvertRSAPrivateKey(privateKey, 0, 0);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
converted = ola.ConvertRSAPrivateKey(private_key, 0, 0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.ConvertRSAPrivateKey(privateKey, 0, 0);cpp
var ola = com("OlaPlug.OlaSoft")
ola.ConvertRSAPrivateKey(privateKey, 0, 0);vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.ConvertRSAPrivateKey(privateKey, 0, 0);text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.ConvertRSAPrivateKey(privateKey, 0, 0);aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.ConvertRSAPrivateKey(privateKey, 0, 0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.ConvertRSAPrivateKey(privateKey, 0, 0);cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.ConvertRSAPrivateKey(privateKey, 0, 0);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = ConvertRSAPrivateKey(instance, privateKey, 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 ConvertRSAPrivateKey(long ola, string privateKey, int inputType, int outputType);
long instance = CreateCOLAPlugInterFace();
long ptr = ConvertRSAPrivateKey(instance, privateKey, 0, 0);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string converted = 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.ConvertRSAPrivateKey(instance, private_key, 0, 0)返回值
| 返回值 | 说明 |
|---|---|
非 0 | 成功,返回 转换后的私钥字符串的指针。 |
0 | 失败。 |
