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. Android群英传》读书笔记 (1) 第一章 Android体系与系统架构 + 第二章 Android开发工具新接触

    第一章 Android体系与系统架构 1.Dalvik 和 ARTDalvik好比是一辆可折叠的自行车,平时是折叠的,只有骑的时候,才需要组装起来用.ART好比是一辆组装好了的自行车,装好就可以骑了. ...

  2. Manacher算法求回文半径

    http://wenku.baidu.com/link?url=WFI8QEEfzxng9jGCmWHoKn0JBuHNfhZ-tKTDMux34CeY8UNUwLVPeY5HA3TyoKU2XegX ...

  3. supervisor 部署文档

    supervisor 部署文档 supervisor 需要Python支持,如果不用系统的supervisor,单独安装python python 安装 #依赖 yum install python- ...

  4. 什么是mimeType?

    因特网多媒体邮件扩展标示内容是什么格式.告诉浏览器或者server如何解析该数据http的请求和相应都含有一个mimeType字段 =>content-type(通用首部)

  5. (转)织梦dedecms模板。如何让type='image'和不带type='image'的文章同时出现在列表里。

    “节日歌圩”栏目是有内容的,但是文章没有缩略图所以没有在频道首页显示出来,我现在想要有缩略图的文章自然显示,没有缩略图的文章也能出现标题列表(依然按照一行4个标题,可以用一张“无缩略图”的图片来代替缩 ...

  6. Hadoop配置项整理(mapred-site.xml)【转】

    本文转自:http://slaytanic.blog.51cto.com/2057708/1101360 name value Description hadoop.job.history.locat ...

  7. 启动php-fpm时报错

    [root@localhost ~]# /usr/local/php/sbin/php-fpm [06-Aug-2012 19:17:53] ALERT: [pool www] pm.min_spar ...

  8. sql plus 和 pl/sql无法连接远程oracle数据库

    前言:安装完oracle客户端后,可能会出现sql plus 和 pl/sql无法连接远程oracle数据库的情况,可能是以下原因: 针对sql plus连接不上: 1 可能原因:之前安装过oracl ...

  9. 重新开始学习javase_IO

    一,认识IO 通过数据流.序列化和文件系统提供系统输入和输出. 流是一个很形象的概念,当程序需要读取数据的时候,就会开启一个通向数据源的流,这个数据源可以是文件,内存,或是网络连接.类似的,当程序需要 ...

  10. 给出2n+1个数,其中有2n个数出现过两次,如何用最简便的方法找出里面只出现了一次的那个数(转载)

    有2n+1个数,其中有2n个数出现过两次,找出其中只出现一次的数 例如这样一组数3,3,1,2,4,2,5,5,4,其中只有1出现了1次,其他都是出现了2次,如何找出其中的1? 最简便的方法是使用异或 ...