C语言加解密系统

这是整个程序的框架。流程图和注册和登录的代码如下:int doPublishBulletin(){ printf("\n\n▽▽▽正在执行发布公告事件!▽▽▽\n\n"); // 等待用户输入待发送的公告信息 char message[500] = "\0"; printf("请输入公告内容(100字以内):\n"); scanf("%[^\n]", message); fflush(stdin); // 等待用户输入自己的私钥(d
摘要由CSDN通过智能技术生成

这是整个程序的框架。

流程图和注册和登录的代码如下:

#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(){

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LMX---青铜选手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值