资源简介

本程序在UDP传输情况下使用DES对固定字符串进行加密传输,(字符串可以自行修改程序进行手动输入)

资源截图

代码片段和文件信息

//--------------------------------------------------------------------//
//                作者:刘文涛                                        //
//                书籍:《网络安全编程技术与实例》                    //
//--------------------------------------------------------------------//
#include 
#include 
#include“des.h“
#pragma comment( lib “ws2_32.lib“ )  
#define BUFFERSIZE 32
void main()
{   
    CDesOperate cDes;
    char strEncryBuffer[BUFFERSIZE];
    int nLen=BUFFERSIZE;
    char *pKey=“1234“;
    
    WSADATA wsaData;
    SOCKET ClientSocket;
    SOCKADDR_IN ServerAddr;
    int ServerPort = 52659;
    char *SendBuffer = “Hello World!“;
    char ReceiveBuffer[1024] = ““;
    int Result;
    if ((Result = WSAStartup(MAKEWORD(2 2) &wsaData)) != 0)
    {
        printf(“WSAStartup failed with error %d\n“ Result);
        return ;
    }
    ClientSocket = socket(AF_INET SOCK_DGRAM IPPROTO_UDP);
    if (ClientSocket < 0)
    {
        printf(“socket failed with error %d\n“ WSAGetLastError());
        return ;
    }
    ServerAddr.sin_family = AF_INET;
    ServerAddr.sin_port = htons(ServerPort);
    ServerAddr.sin_addr.s_addr = inet_addr(“127.0.0.1“);
    int len;
    cDes.Encry(SendBufferstrlen(SendBuffer)strEncryBuffernLenpKey8);//加密语句
    if (len =sendto(ClientSocket strEncryBufferstrlen(strEncryBuffer)0(SOCKADDR*)&ServerAddrsizeof(ServerAddr))<0)//发送
    {
        printf(“sendto failed with error %d\n“ WSAGetLastError());
        return ;
    }
    else
    {
        printf(“Send the data:%s\n“ SendBuffer);
printf(“数据加密后发送,data:%s\n“strEncryBuffer);//经过加密的“hello world”updclient端的数据显示

    }
    int FromAddrSize = sizeof(ServerAddr);
    memset(ReceiveBuffer 0 sizeof(ReceiveBuffer));
    memset(&ServerAddr 0 sizeof(ServerAddr));
cDes.Encry(SendBufferstrlen(SendBuffer)strEncryBuffernLenpKey8);
    if (len = recvfrom(ClientSocket ReceiveBuffer 1024 0 (SOCKADDR*) &ServerAddr &FromAddrSize) < 0)
    {
        printf(“recvfrom failed with error %d\n“ WSAGetLastError());
        return ;
    }
    else
    {
        printf(“Received Data:%s From :%s\n“ ReceiveBuffer inet_ntoa(ServerAddr.sin_addr));
    }
    if (closesocket(ClientSocket) == SOCKET_ERROR)
    {
        printf(“closesocket failed with error %d\n“ WSAGetLastError());
    }
    if (WSACleanup() == SOCKET_ERROR)
    {
        printf(“WSACleanup failed with error %d\n“ WSAGetLastError());
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      49152  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\debug\udpclient.exe

     文件     344136  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\debug\udpclient.ilk

     文件     379904  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\debug\udpclient.pdb

     文件       2567  2014-05-29 11:51  UDP+DES加密+socket编程\udpclient\udpclient\client.cpp

     文件       9990  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\BuildLog.htm

     文件      40001  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\client.obj

     文件         65  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\mt.dep

     文件        403  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\udpclient.exe.embed.manifest

     文件        468  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\udpclient.exe.embed.manifest.res

     文件        385  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\udpclient.exe.intermediate.manifest

     文件     306176  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\vc80.idb

     文件      86016  2014-05-29 11:55  UDP+DES加密+socket编程\udpclient\udpclient\Debug\vc80.pdb

     文件      13775  2014-05-29 11:07  UDP+DES加密+socket编程\udpclient\udpclient\des.h

     文件       4031  2014-05-29 11:07  UDP+DES加密+socket编程\udpclient\udpclient\udpclient.vcproj

     文件       1427  2014-05-29 13:25  UDP+DES加密+socket编程\udpclient\udpclient\udpclient.vcproj.DADI-20140419ZF.hongai.user

     文件    6712320  2014-05-29 13:25  UDP+DES加密+socket编程\udpclient\udpclient.ncb

     文件        892  2014-05-29 11:05  UDP+DES加密+socket编程\udpclient\udpclient.sln

    ..A..H.      8704  2014-05-29 13:25  UDP+DES加密+socket编程\udpclient\udpclient.suo

     文件      49152  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\debug\udpservice.exe

     文件     341192  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\debug\udpservice.ilk

     文件     379904  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\debug\udpservice.pdb

     文件       9666  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\BuildLog.htm

     文件         65  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\mt.dep

     文件      39634  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\sevice.obj

     文件        403  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\udpservice.exe.embed.manifest

     文件        468  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\udpservice.exe.embed.manifest.res

     文件        385  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\udpservice.exe.intermediate.manifest

     文件     306176  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\vc80.idb

     文件      86016  2014-05-29 11:54  UDP+DES加密+socket编程\udpservice\udpservice\Debug\vc80.pdb

     文件      13775  2014-05-29 11:02  UDP+DES加密+socket编程\udpservice\udpservice\des.h

............此处省略18个文件信息

评论

共有 条评论