Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Build your own cryptographically safe server/client protocol

, 21 Jun 2006 CPOL
This article presents all you need to implement your own secure protocol using variable keysize RSA encryption/decryption, digital signing, multi precision library, Diffie-Hellman key exchange, Rijndael, and more. Everything is converged into a secure IOCP client/server chat server.
// IOCPBuffer.h: interface for the CIOCPBuffer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_IOCPBUFFER_H__87DEF694_32D6_4F21_8FF5_E16184A9CDC3__INCLUDED_)
#define AFX_IOCPBUFFER_H__87DEF694_32D6_4F21_8FF5_E16184A9CDC3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


/*
* This Class is used to pass around the buffer and the operation that 
* is done asynchronously. 
*
*/
#include "IOCPS.h"

class CIOCPBuffer   
{
public:
	void Init();	
	PBYTE GetPayLoadBuffer();
	BOOL CreatePackage(BYTE Type, UINT iFilesize,UINT iBufferSize, const BYTE *const pData);
	BOOL GetPackageInfo(BYTE &Type, BYTE &key, CString &stxt);
	BOOL CreatePackage(BYTE Type, BYTE key,  CString stxt);
	BOOL GetPackageInfo(BYTE &Type,BYTE &key1,BYTE &key2,BYTE &key3, CString &stxt);
	// Used with overlapped.. 
	OVERLAPPED			m_ol;
	BOOL Flush(UINT nBytesToRemove);
	POSITION GetPosition();
	void SetPosition(POSITION pos);    
	WSABUF * GetWSABuffer();
	// sets the SequenceNumber of this object. 
	void SetSequenceNumber(int nr);
	// Get The sequensNumber of the buffer object. 
	int GetSequenceNumber();
	// Setup Different Types in buffer. 
	void SetupWrite();
	void SetupRead();
	void SetupZeroByteRead();
	int GetOperation();
	void SetOperation(int op);
	void EmptyUsed();
	UINT Use(UINT nSize);
	UINT GetUsed();
	//UINT GetSize();
	BOOL IsValid();
	// DUMP the buffer. (For Debug)
	void DUMP();
	// Write different types of variabels to the buffer
	BOOL AddData(const BYTE * pData,UINT nSize);
	BOOL AddData(const char * pData,UINT nSize);
	BOOL AddData(BYTE data);
	BOOL AddData(UINT data);
	BOOL AddData(unsigned short data);

	//  Create different type of Packages in the Buffer..
	BOOL CreatePackage(CString stxt);
	BOOL CreatePackage(BYTE Type,CString stxt);
	BOOL CreatePackage(BYTE Type,UINT nData, CString stxt);
	BOOL CreatePackage(BYTE Type);
	BOOL CreatePackage(BYTE Type,BYTE key1,BYTE key2,BYTE key3, CString stxt);
	//
	// Get information from the Package.. 
	//
	// Reurns the Pakage size if possible -1 if error. 
	UINT GetPackageSize();
	// Gets The package Type returns 255 if error. 
	BYTE GetPackageType();
	// Reads the info from a package created with CreatePackage(CString stxt);
	BOOL GetPackageInfo(CString &stxt);
	// Reads the info from a package created with CreatePackage(BYTE Type,CString stxt);
	BOOL GetPackageInfo(BYTE &Type, CString &stxt);
	// Reads the info from a package created with CreatePackage(BYTE Type,CString stxt);
	BOOL GetPackageInfo(BYTE &Type,UINT &nData, CString &stxt);
	// returns A pointer to the Buffer 
	PBYTE GetBuffer();
	CIOCPBuffer();
	virtual ~CIOCPBuffer();

private:
	int m_iSequenceNumber;
	// The Type of Operation. 
	int		m_Operation;
	// Size of the Buffer 
	//UINT	m_nSize;
	// number of bytes that are Used. 
	UINT    m_nUsed;
	// The buffer. 
	BYTE m_Buffer[MAXIMUMPACKAGESIZE];
	//Holds the Buffer Used for send/receive
	WSABUF m_wsabuf;
	// Used to remove the buffer from the queue. 
	POSITION m_pPos;
};

#endif // !defined(AFX_IOCPBUFFER_H__87DEF694_32D6_4F21_8FF5_E16184A9CDC3__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

spinoza
Program Manager
Sweden Sweden
Amin Gholiha.
Education:
- Master of Science in Information Technology.
- Degree of Master of Education.
Knowledge/interest: programming (.NET,Visual, C#/C++), neural network, mathematical modeling, signal processing, sequence analysis, pattern recognition,robot technology, system design, security and business management systems. For business proposal email Gholiha@rocketmail.com, all other emails will be ignored.
Current Work:
Project Manager
www.easysoft.nu (the best free e-signature tool)

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150123.1 | Last Updated 21 Jun 2006
Article Copyright 2006 by spinoza
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid