免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 756 | 回复: 0
打印 上一主题 下一主题

[求助]请问别人给的cgi程序怎么改写成php可用的? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-05-19 16:11 |只看该作者 |倒序浏览
程序如下

example.cpp
#include <stdio.h>;
#include <memory.h>;
#include "Sign_Lib.h"
#define PRIVATEKEYFILE "/root/privatekey.txt"
#define PUBLICKEYFILE "/root/publickey.txt"
#define SGNMGLENGTH 257
void main(void)
{
int verify_result=0;
bool result;
char message[255];
char sgnmessage[SGNMGLENGTH];
memset(message,0,255);
memset(sgnmessage,0,SGNMGLENGTH);

/*-------------以下是从请求中取得参数部分------------------*/
cgiFormStringNoNewlines("billno", c_billno, 50);
cgiFormStringNoNewlines("amount", c_amount, 20);
cgiFormStringNoNewlines("date", c_date, 20);
cgiFormStringNoNewlines("succ", c_succ, 1);
cgiFormStringNoNewlines("signature", c_signature, 256);
//注意:signature的长度一定是256个Byte
/*----------------------------------------------------------*/

sprintf(message,"%s%s%s%s",c_billno,c_amount,c_date,c_succ);
/*用billno,amount,date,succ生成原始消息*/
result = VerifyMessage(PUBLICKEYFILE,message,c_signature,&verify_result);
/*函数VerifyMessage的返回值result如果为true且verify_result为0时,表示成功,result为false表示失败*/
/*如果result为false,检查错误代码verify_result*/
/*verify_result为1,表示签名不正确*/
/*verify_result为2,表示没有生成消息文件*/
/*verify_result为3,表示没有生成签名文件*/
/*verify_result为4,表示签名长度错*/
printf("%d\r\n",verify_result);
if((result==1)&&(verify_result==0))
printf("It's OK,Verifying Message succeed!\r\n";
}
=====================
Sign_Lib.h

#ifndef SIGN_LIB_H
#define SIGN_LIB_H

#define MESSAGEFILE "/root/message.txt"
#define SIGNATUREFILE "/root/signature.txt"

extern "C" bool VerifyMessage(const char* publickey,const char*message, const char* signature, int *result);
/*
publickey 为公钥文件全路经
message 为原始消息
signature 为消息的签名
result 如果有错误发生,为返回的错误代码
函数返回值为true且result=0,表示签名正确;否则表示签名不正确。
这时可以参考result的值检查错误原因
result=1,表示签名与原始消息不符合
result=2,表示没有生成消息问件
result=3,表示没有生成签名文件
result=4,表示签名的长度错误
*/

#endif
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP