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. 使用jq深入研究轮播图特性

    网站轮播图 太耳熟的词了  基本上做pc端的 主页绝壁会来一个轮播图的特效 轮播图他一个页面页面的切换,其实的原理是通过css的定位 ,定位到一起,第一张首先显示,其余默认隐藏. 今天我实现的这个轮播 ...

  2. 使用top工具,找出消耗CPU 较多的进程

    1.使用top工具,找出消耗CPU 较多的进程 [oracle@cuug ~]$ top top - 10:48:27 up 23:15,  4 users,  load average: 1.09, ...

  3. 你好,C++(12)如何管理多个类型相同性质相同的数据?3.6 数组

    3.6  数组 学过前面的基本数据类型之后,我们现在可以定义单个变量来表示单个的数据.例如,我们可以用int类型定义变量来表示公交车的216路:可以用float类型定义变量来表示西红柿3.5元一斤.但 ...

  4. hdu 2460 poj 3694 (双联通+LCA)

    在给出的两个点上加一条边,求剩下桥的数量,,不会LCA在线,就用了最普通的,先Tarjan双联通缩点,然后将缩完的图建成一棵树,树的所有边就是桥了,如果在任意两点间加一条边的话,那么从两点到最近公共祖 ...

  5. C语言零移位操作

    给定一个整形数组要求把其中的零元素移动到数组的末尾 非零元顺序保持不变 以下采用两种方法实现 #include <stdlib.h> #include <stdio.h> #i ...

  6. (转)Android Studio系列教程一下载与安装 背景Android Studio VS Eclipse准备下载创建HelloWorld项目

    背景 相信大家对Android Studio已经不陌生了,Android Studio是Google于2013 I/O大会针对Android开发推出的新的开发工具,目前很多开源项目都已经在采用,Goo ...

  7. OpenGL旋转平移 变换

    #include<gl/glut.h> #include<gl/GL.h> #include<gl/GLU.h> #include<math.h> #i ...

  8. 自定义JQuery插件之 beforeFocus

    <html> <head> <title></title> <script type="text/javascript" sr ...

  9. mybatis中association的column传入多个参数值

    顾名思义,association是联合查询. 在使用association中一定要注意几个问题.文笔不好,白话文描述一下. 1: <association property="fncg ...

  10. 发一个自己写的php框架

    这个框架是我在学习php初期练手写的,现在分享出来希望对初学者有一定帮助. 目录结构:app:网站系统目录    ---common:网站配置目录    ---tpl:网站模板目录    ---log ...