惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
V
V2EX
B
Blog RSS Feed
有赞技术团队
有赞技术团队
博客园 - Franky
美团技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
云风的 BLOG
云风的 BLOG
L
LangChain Blog
GbyAI
GbyAI
The Cloudflare Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Stack Overflow Blog
Stack Overflow Blog
博客园 - 【当耐特】
The Register - Security
The Register - Security
大猫的无限游戏
大猫的无限游戏
D
Docker
Vercel News
Vercel News
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
N
Netflix TechBlog - Medium
博客园_首页
A
About on SuperTechFans
J
Java Code Geeks
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
Recent Announcements
Recent Announcements
G
Google Developers Blog
小众软件
小众软件
博客园 - 叶小钗
WordPress大学
WordPress大学
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
F
Full Disclosure
Jina AI
Jina AI
H
Help Net Security

博客园 - KeithDan

Windows 8开发 WinRT 对ZIP文件解压缩及文件夹的ZIP压缩 wp应用发布,金宝贝点读 WP7游戏分裂细胞 WP7游戏方块夺宝 C#手工解析XML xeno tactic 2 完整版 Lua扫雷 惊人!天下奇闻“鹏” 今天很郁闷 HighLightCode1.2——开源项目 代码着色--关于循环与分组 代码着色--开源系列 非托管dll的需要注意的地方 page_load执行两次 transfer object (3) transfer object (2) transfer object (1) 中国象棋(网络版) 人生的阶梯
利用非托管dll实现多平台加密
KeithDan · 2007-11-30 · via 博客园 - KeithDan

我们使用delphi作为win32开发,编写的rsa加密,需要在服务器使用公钥加密,而在客户端使用私钥解密.
本程序使用的加密dll为delphi所写,包含3个函数,其函数原形如下:

function CreateKey(var key:RsaKey):boolean;export; stdcall;
  function EncryptRsa(key:pchar;commkey:pchar;text:pchar):pchar;export; stdcall;
  function DecryptRsa(key:pchar;commkey:pchar;text:pchar):pchar;export; stdcall;

其中,在rsakey类型原形为

type RsaKey=packed record
publickey:pChar;
privatekey:pChar;
commkey:pchar;
end;

在C#中首先需要DllImport将dll导入,并声明其外部方法.

 public struct RsaKey
        
{
            
public string publicKey;
            
public string privateKey;
            
public string commKey;
        }

        [DllImport(
@"Security.dll")]
        
public static extern string EncryptRsa(string key, string commkey, string text);
        [DllImport(
@"Security.dll")]
        
public static extern string DecryptRsa(string key, string commkey, string text);
        [DllImport(
@"Security.dll")]
        
public static extern bool CreateKey(ref RsaKey key);


其中Rsakey对应struct.
其中的测试demo大家可以下载,包含c#以及delphi

--------------------------------
C#Demo DelphiDemo