1. 浏览器安全控件是如果支付宝一样结合web程序密码数据安全处理的程序,采用C++语言开发
  2. 通常的安全控件分为两种,一种是指支持IE内核的浏览器,一种支持所有内核的浏览器,支付宝采用的是支持所有内核的浏览器,但是为了使用IE内核浏览器的一些特性支付宝继续保留IE内核版本
  3. 安全控件密码输入有两种方式,一种是虚拟键盘(大多银行使用),另一种是自绘密码控件支付宝,财付通句使用此种方

下面讲一下加密方式

des加密,这个种加密算法适合于java做可逆加密,使用方便

#ifndef Des_H
#define Des_H //! enum bool{false,true};
/*!
if bool is not supported,use this or just replace with char and use 1 for true,0 for false;
@see enum {ENCRYPT,DECRYPT};
*/
enum {ENCRYPT,DECRYPT};
/*@brief 16圈子密钥*/
static bool SubKey[][][];// 16圈子密钥
/*@brief 3次DES标志*/
static bool Is3DES;// 3次DES标志
static char Tmp[];
static char deskey[];
typedef bool (*PSubKey)[][]; class _declspec(dllexport) Des
{
public:
Des();
~Des();
//! Type—ENCRYPT:加密,DECRYPT:解密
/*!
输出缓冲区(Out)的长度 >= ((datalen+7)/8)*8,即比datalen大的且是8的倍数的最小正整数
In 可以= Out,此时加/解密后将覆盖输入缓冲区(In)的内容
当keylen>8时系统自动使用3次DES加/解密,否则使用标准DES加/解密.超过16字节后只取前16字节
@see bool Des_Go(char *Out,char *In,long datalen,const char *Key,int keylen,bool Type = ENCRYPT);
*/ bool Des_Go(char *Out,char *In,long datalen,const char *Key,int keylen,bool Type = ENCRYPT); private:
/*! @brief 标准DES加/解密
@see static void DES(char Out[8], char In[8], const PSubKey pSubKey, bool Type);
*/
static void DES(char Out[], char In[], const PSubKey pSubKey, bool Type);//标准DES加/解密
/*! @brief 设置密钥
@see static void SetKey(const char* Key, int len);
*/
static void SetKey(const char* Key, int len);// 设置密钥
/*! @brief 设置子密钥
@see static void SetSubKey(PSubKey pSubKey, const char Key[8]);
*/
static void SetSubKey(PSubKey pSubKey, const char Key[]);// 设置子密钥
/*! @brief f 函数
@see static void F_func(bool In[32], const bool Ki[48]);
*/
static void F_func(bool In[], const bool Ki[]);// f 函数
/*! @brief S 盒代替
@see static void S_func(bool Out[32], const bool In[48]);
*/
static void S_func(bool Out[], const bool In[]);// S 盒代替
/*! @brief 变换
@see static void Transform(bool *Out, bool *In, const char *Table, int len);
*/
static void Transform(bool *Out, bool *In, const char *Table, int len);// 变换
/*! @brief 异或
@see static void Xor(bool *InA, const bool *InB, int len);
*/
static void Xor(bool *InA, const bool *InB, int len);// 异或
/*! @brief 循环左移
@see static void RotateL(bool *In, int len, int loop);
*/
static void RotateL(bool *In, int len, int loop);// 循环左移
/*! @brief 字节组转换成位组
@see static void ByteToBit(bool *Out, const char *In, int bits);
*/
static void ByteToBit(bool *Out, const char *In, int bits);// 字节组转换成位组
/*! @brief 位组转换成字节组
@see static void BitToByte(char *Out, const bool *In, int bits);
*/
static void BitToByte(char *Out, const bool *In, int bits);// 位组转换成字节组 };
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
#endif
#include "memory.h"
#include "Des.h" ////////////////////////////////////////////////////////////////////////// // initial permutation IP
const static char IP_Table[] = {
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , ,
};
// final permutation IP^-1
const static char IPR_Table[] = {
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , ,
};
// expansion operation matrix
static const char E_Table[] = {
, , , , , , , , , , , ,
, , , , , , , , , , , ,
, , , , , , , , , , , ,
, , , , , , , , , , ,
};
// 32-bit permutation function P used on the output of the S-boxes
const static char P_Table[] = {
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , ,
};
// permuted choice table (key)
const static char PC1_Table[] = {
, , , , , , , , , , , , , ,
, , , , , , , , , , , , , ,
, , , , , , , , , , , , , ,
, , , , , , , , , , , , ,
};
// permuted choice key (table)
const static char PC2_Table[] = {
, , , , , , , , , , , ,
, , , , , , , , , , , ,
, , , , , , , , , , , ,
, , , , , , , , , , ,
};
// number left rotations of pc1
const static char LOOP_Table[] = {
,,,,,,,,,,,,,,,
};
// The (in)famous S-boxes
const static char S_Box[][][] = {
// S1
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
// S2
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
// S3
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
// S4
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
// S5
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
// S6
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
// S7
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
// S8
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , ,
}; //////////////////////////////////////////////////////////////////////////
// Code starts:
//////////////////////////////////////////////////////////////////////////
Des::Des()
{ }
Des::~Des()
{ }
bool Des::Des_Go(char *Out, char *In, long datalen, const char *Key, int keylen, bool Type)
{
if( !( Out && In && Key && (datalen=(datalen+)&0xfffffff8) ) )
return false;
SetKey(Key, keylen);
if( !Is3DES ) { // 1次DES
for(long i=,j=datalen>>; i<j; ++i,Out+=,In+=)
DES(Out, In, &SubKey[], Type);
} else{ // 3次DES 加密:加(key0)-解(key1)-加(key0) 解密::解(key0)-加(key1)-解(key0)
for(long i=,j=datalen>>; i<j; ++i,Out+=,In+=) {
DES(Out, In, &SubKey[], Type);
DES(Out, Out, &SubKey[], !Type);
DES(Out, Out, &SubKey[], Type);
}
}
return true;
}
void Des::SetKey(const char* Key, int len)
{
memset(deskey, , );
memcpy(deskey, Key, len>?:len);
SetSubKey(&SubKey[], &deskey[]);
Is3DES = len> ? (SetSubKey(&SubKey[], &deskey[]), true) : false;
}
void Des::DES(char Out[], char In[], const PSubKey pSubKey, bool Type)
{
static bool M[], tmp[], *Li=&M[], *Ri=&M[];
ByteToBit(M, In, );
Transform(M, M, IP_Table, );
if( Type == ENCRYPT ){
for(int i=; i<; ++i) {
memcpy(tmp, Ri, );
F_func(Ri, (*pSubKey)[i]);
Xor(Ri, Li, );
memcpy(Li, tmp, );
}
}else{
for(int i=; i>=; --i) {
memcpy(tmp, Li, );
F_func(Li, (*pSubKey)[i]);
Xor(Li, Ri, );
memcpy(Ri, tmp, );
}
}
Transform(M, M, IPR_Table, );
BitToByte(Out, M, );
}
void Des::SetSubKey(PSubKey pSubKey, const char Key[])
{
static bool K[], *KL=&K[], *KR=&K[];
ByteToBit(K, Key, );
Transform(K, K, PC1_Table, );
for(int i=; i<; ++i) {
RotateL(KL, , LOOP_Table[i]);
RotateL(KR, , LOOP_Table[i]);
Transform((*pSubKey)[i], K, PC2_Table, );
}
}
void Des::F_func(bool In[], const bool Ki[])
{
static bool MR[];
Transform(MR, In, E_Table, );
Xor(MR, Ki, );
S_func(In, MR);
Transform(In, In, P_Table, );
}
void Des::S_func(bool Out[], const bool In[])
{
for(char i=,j,k; i<; ++i,In+=,Out+=) {
j = (In[]<<) + In[];
k = (In[]<<) + (In[]<<) + (In[]<<) + In[];
ByteToBit(Out, &S_Box[i][j][k], );
}
}
void Des::Transform(bool *Out, bool *In, const char *Table, int len)
{
for(int i=; i<len; ++i)
Tmp[i] = In[ Table[i]- ];
memcpy(Out, Tmp, len);
}
void Des::Xor(bool *InA, const bool *InB, int len)
{
for(int i=; i<len; ++i)
InA[i] ^= InB[i];
}
void Des::RotateL(bool *In, int len, int loop)
{
memcpy(Tmp, In, loop);
memcpy(In, In+loop, len-loop);
memcpy(In+len-loop, Tmp, loop);
}
void Des::ByteToBit(bool *Out, const char *In, int bits)
{
for(int i=; i<bits; ++i)
Out[i] = (In[i>>]>>(i&)) & ;
}
void Des::BitToByte(char *Out, const bool *In, int bits)
{
memset(Out, , bits>>);
for(int i=; i<bits; ++i)
Out[i>>] |= In[i]<<(i&);
}
//////////////////////////////////////////////////////////////////////////
// Code ends.
//////////////////////////////////////////////////////////////////////////

具体流程或者开发中遇到的问题可以留言

QQ:2410541231

安全控件开发原理分析 支付宝安全控件开发 C++的更多相关文章

  1. Android控件TextView的实现原理分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8636153 在前面一个系列的文章中,我们以窗口 ...

  2. 线程间操作无效: 从不是创建控件“”的线程访问它~~~的解决方法~ 线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析

    看两个例子,一个是在一个进程里设置另外一个进程中控件的属性.另外一个是在一个进程里获取另外一个进程中控件的属性. 第一个例子 最近,在做一个使用线程控制下载文件的小程序(使用进度条控件显示下载进度)时 ...

  3. Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现

    Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现 2015-03-10 22:38 28419人阅读 评论(17) 收藏 举报  分类: Android ...

  4. iOS开发UI篇—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

  5. iOS开发UI基础—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

  6. HTML5 移动应用开发环境搭建及原理分析

    开发环境搭建: 一.Android 开发平台搭建 安装java jdk:\\10.194.151.132\Mewfile\tmp\ADT 配置java jdk 1)  新建系统变量,JAVA_HOME ...

  7. C/S模式开发中如何利用WebBrowser控件制作导航窗体

    原文:C/S模式开发中如何利用WebBrowser控件制作导航窗体 转自: CSDN 相信不少同学们都做过MIS系统的开发,今天这里不讨论B/S模式开发的问题.来谈谈winform开发.用过市面上常见 ...

  8. UiAutomator源码分析之获取控件信息

    根据上一篇文章<UiAutomator源码分析之注入事件>开始时提到的计划,这一篇文章我们要分析的是第二点: 如何获取控件信息 我们在测试脚本中初始化一个UiObject的时候通常是像以下 ...

  9. 支付宝app支付java后台流程、原理分析(含nei wang chuan tou)

    java版支付宝app支付流程及原理分析 本实例是基于springmvc框架编写     一.流程步骤         1.执行流程           当手机端app(就是你公司开发的app)在支付 ...

随机推荐

  1. Log4net 配置注意事项

    1. 首先引入Log4net程序集 2.修改webconfig配置文件 在 configuration 节点下面添加如下节点 <configSections> <section na ...

  2. Alibaba FastJson

    import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSONObject class Test { static main(arg ...

  3. Objective-C学习篇04—多态

    多态 多态的概念 有这样一个例子.早上我和同事说口渴了.结果:A同事拿着我的水杯去给我接了一杯水.B同事顺手在饮水机上拿了一次性纸杯给我接了杯水.C同事给了我一瓶他早上刚买的饮料.同事们得到的是同样的 ...

  4. nodejs概论(实操篇)

    什么是模块? 模块分为原生模块(node.jsAPI提供的原生模块,在启动时已经被加载)和 文件模块(动态加载模块,主要由原生模块module来实现和完成.通过调 用node.js的require方法 ...

  5. javaScript 手写图片轮播

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. JS中区分参数方法

    实现功能:在使用cocosjs制作游戏过程中,很多东西都可以重复使用,例如菜单栏等等.今天尝试写了一个自定义的Js文件用作菜单方便以后使用. 将菜单按钮,以及触发事件作为参数生成一个层 直接在游戏中使 ...

  7. WebService笔记-Schema约束

                        Schema约束 俗话说得好 好记性不如烂笔头. 看了下WebService视频,觉得还是得下笔记. 观看的视频地址:http://edu.51cto.com/ ...

  8. ext之关键字mixins、statics、require

    1.mixins 说明:类似于面向对象中的多继承 <script type="text/javascript"> Ext.onReady(function () { / ...

  9. ActionResult派生类

    类名 抽象类 父类 功能 ContentResult 根据内容的类型和编码,数据内容. EmptyResult 空方法. FileResult abstract 写入文件内容,具体的写入方式在派生类中 ...

  10. uva 10976 Fractions Again(简单枚举)

    10976 Fractions Again It is easy to see that for every fraction in the form 1 k (k > 0), we can a ...