这是整个程序的框架。
流程图和注册和登录的代码如下:![](https://img-blog.csdnimg.cn/f16019fef93340b5bf518364f80abcd9.png)
![](https://img-blog.csdnimg.cn/b9a6b5a9f7ed4c65a817d8ffb03ddc17.png)
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include "Authority.h"
#include "../algorithm/RSA.h"
#include "../algorithm/MD5.h"
#include "../common/global.h"
#include "../common/menu.h"
//功能:将用户输入的密码进行存储,并且用*号显示
void ScanStar(char *str, int strLen)
{
int i = 0;
while ((str[i++] = getch()) != '\r') {
printf("*");
if (i >= strLen) break;
}
str[i-1] = 0x00;
printf("\n");
}
//以16进制方式打印目标字符串到屏幕
void Print_HexData(char *src, long len)
{
int i = 0;
for (;i < len; i++){
printf("%02X", (unsigned char)src[i]);
}
}
//注册
int doPublishBulletin()
{
printf("\n\n▽▽▽正在执行发布公告事件!▽▽▽\n\n");
// 等待用户输入待发送的公告信息
char message[500] = "\0";
printf("请输入公告内容(100字以内):\n");
scanf("%[^\n]", message);
fflush(stdin);
// 等待用户输入自己的私钥(d,n)
int d = 0;
while(1){
printf("请输入你的私钥:\n");
scanf("%d", &d);
fflush(stdin);
if(d > 0)
break;
printf("请输入有效数字!\n\n");
}
//计算公告信息的MD5值
char message_MD5[17] = "\0";
int message_len = strlen(message);
md5(message, message_len, message_MD5);
//使用私钥(d,n)对MD5值进行RSA加密得到签名
//此处为了使用同一个加密函数,所以将d赋值给rsaPubKey.e
RsaPubKey rsaPubKey;
rsaPubKey.e = d;
rsaPubKey.n = g_loginUserInfo.nKey;
long* message_MD5_en =(long*)malloc(sizeof(long)*16);
memset(message_MD5_en, 0x00, sizeof(long)*16);
RsaEncipher(message_MD5, 16, message_MD5_en, rsaPubKey);
//将发送者用户名、公告信息、签名和发送时间写入全局变量和bulletin.db
stBulletinInfo *pBullInfo = (stBulletinInfo*)malloc(sizeof(stBulletinInfo));
memset(pBullInfo, 0x00, sizeof(stBulletinInfo));
strcpy(pBullInfo->sender, g_loginUserInfo.username);
strcpy(pBullInfo->bulletin, message);
//MD5值里可能会出现"\0",所以这里用memcpy
memcpy(pBullInfo->signature, message_MD5_en, sizeof(long)*16);
MakeCurTimeStr(pBullInfo->sendTime);
//写入全局变量
AddBulletinList(g_bulletinList, *pBullInfo);
//写入文件
writeDBFile(FILE_BULLETINLIST, pBullInfo, sizeof(stBulletinInfo));
free(message_MD5_en);
free(pBullInfo);
//提示用户发送公告成功
printf("公告发布成功!\n");
printf("\n△△△发布公告事件执行完成!△△△\n\n");
return 1;
}
int doViewBulletin(){