?? des.h
字號:
// des.h : main header file for the DES DLL
//
#if !defined(AFX_DES_H__AD54EE49_A3F1_44CA_B06C_C8A87B67C7E1__INCLUDED_)
#define AFX_DES_H__AD54EE49_A3F1_44CA_B06C_C8A87B67C7E1__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CDesApp
// See des.cpp for the implementation of this class
//
class CDesApp : public CWinApp
{
public:
CDesApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDesApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CDesApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/*****************************常用函數*************************/
/* 將一個十六進制字節串轉換成 ASCII 碼表示的字符串;
unsigned char *pHex -- 十六進制數字節串首地址;
unsigned char *pASSCHex -- 轉換后的 ASCII 碼表示的字符串的首地址;
注:轉換后pASSCHex的長度是pHex的長度的兩倍,所以要保證長度夠用。
int nLen -- 要轉換的十六進制數的長度(字節數)。
注: 轉換后的結果全部是大寫 ASSC 表示的十六進制數;
程序中不對 pHex 和 pASSCHex 的合法性進行檢查;
也不對數組越界進行檢查。
sample: "\x11\x22\x44\x66"->"11224466" nlen=4
*/
void HexToAscii(unsigned char * pHex, unsigned char * pASSCHex, int nLen);
////////////////////////////////////////////////////////////////////////////////////////////
// 功能: 將一個 ASSC 碼表示的十六進制字符串轉換成十六進制的字節串;
// 輸入參數: pAscii -- 轉換后的 ASCII 碼表示的十六進制字符串的首地址;
// pHex -- 十六進制數字節串首地址;
// nLen -- 要轉換的 ASCII 碼表示的十六進制字符串的長度(字節數)。
// 輸出參數: 空。
// 注: 要求輸入的 ASCII 碼表示的十六進制數的字符個數必須為偶數,因為 轉換后結果的長度要減半。 除了是1 - 9 和 A(a) - F(f) 以外沒有別的字符;
// 程序中不對 pAscii 和 pHex 的合法性進行檢查;
// 也不對數組越界進行檢查。
//長度不對,不是0-9 A-F a-f return false; else return true
//例 "11224455"->"\x11\x22\x44\x55" nlen=8
////////////////////////////////////////////////////////////////////////////////////////////
bool AsciiToHex(unsigned char * pAscii, unsigned char * pHex, int nLen);
/*
功能:CString 轉換成 unsigned char *
輸入:
str :為轉換前的字符穿,字符個數必須是偶數
輸出:
hex :為轉換后的字節數組
hexlen:為轉換后字節數組長度
返回值: 轉換成功返回true,轉換失敗返回false
說明:轉換前字符穿中的字符個數必須為偶數,否則轉換失敗。
此函數依賴于AsciiToHex(unsigned char * pAscii, unsigned char * pHex, int nLen)這個函數。
2006/07/21 修改說明:當轉換前的字符串不是偶數個字符時,在前面補一個0;
作者:2006/07/14 姜玉雷
*/
bool StrToHex(CString str,unsigned char*hex, int & hexlen);
/*
功能:unsigned char* 轉換成 CString
輸入:
hex :轉換前的字節數組
hexlen :轉換前字節數組長度
輸出:
str :轉換后的字符串
說明:此函數依賴于HexToAscii(unsigned char * pHex, unsigned char * pASSCHex, int nLen)這個函數。
作者:2006/07/14 姜玉雷
*/
void HexToStr(unsigned char * hex,int hexlen, CString & str);
/*DES加密
dat:加密前的數據 和 加密后的數據 ,長度8字節;
key1:密鑰;長度8字節
mode:加密模式 0加密;1解密;
*/
void des(BYTE *dat, BYTE *key1, BYTE mode);
/*TDES加密
dat:加密前的數據 和 加密后的數據;長度8字節
key1:密鑰前8字節;
key2:密鑰后8字節;
mode:加密模式 0加密;1解密;
*/
void tri_des(BYTE *dat, BYTE *key1, BYTE *key2, BYTE mode);
//異或運算
//A,B做異或運算結果放在 A 中
void xor(unsigned char *A,unsigned char *B,unsigned char L);
/****************************************************
* 計算MAC(通用) *
* Key:密鑰(8字節/16字節) *
* d_input:計算MAC的輸入數據(inputlen 字節) *
* inputlen:輸入數據的長度 *
* PreData:初始數據(8字節) *
* FillInput: 0:不對輸入數據補值 *
* 1:用80...00對輸入數據補值 *
* T:0x01:單長度MAC計算(密鑰8字節) *
* 0x02:雙長度MAC計算(密鑰16字節) *
* mac:計算結果MAC (4字節) *
*當Key:放到XDATA時會出錯,原因未知 *
*****************************************************/
void TMAC(unsigned char *Key,unsigned char *d_input,BYTE inputlen,
unsigned char *PreData, bool FillInput, BYTE T, unsigned char *mac);
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DES_H__AD54EE49_A3F1_44CA_B06C_C8A87B67C7E1__INCLUDED_)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -