加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

跨平台C++ Des加密类库,des.h

(2005-05-26 11:17:44)
标签:

杂谈

分类: 计算机与 Internet

当使用字符串作为密钥时,依赖与前面的md5类库

#ifndef _DES_H_
#define _DES_H_

#include <string>
#include "md5.h"
using namespace std;

//////////////////////////////////////////////////////////////////////////
class CDes
{
protected:
 bool SubKey[16][48];
 void F_func(bool In[32], const bool Ki[48]);// f 函数
 void S_func(bool Out[32], bool In[48]);// S 盒代替
 void Transform(bool *Out, bool *In, const char *Table, int len);// 变换
 void Xor(bool *InA, const bool *InB, int len);// 异或
 void RotateL(bool *In, int len, int loop);// 循环左移
 void ByteToBit(bool *Out, const char *In, int bits);// 字节组转换成位组
 void BitToByte(char *Out, const bool *In, int bits);// 位组转换成字节组
public:
 //加密文本,产生base64加密结果
 string Des_EncryptText(string text,string key);
 //解密文本,由base64解密成原始字符串
 string Des_DecryptText(string text,string key);

 // 加/解密 一个连续内存块,要求len必须8倍数
 void Des_Full(unsigned char* pdata,size_t len, bool bENCRYPT);
 // 加/解密 一个8字节块
 void Des_Block(char* Out, char* In, bool bENCRYPT);
 // 设置密钥
 void Des_SetKey(const char Key[8]);
 void Des_SetKey(const string &Key);
 //当前使用的key,即常见的56bit密码
 char FullKey[8];
};
//////////////////////////////////////////////////////////////////////////
#endif

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有