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. 1_Linux_目录简介

    1. Linux中所以内容以文件形式保存,包括硬件,所以在用命令行配置文件时,该配置仅仅是临时生效.   2. Linux不靠扩展名区分类型,而是靠文件权限.之所以有扩展名是为了便于管理. .rpm二 ...

  2. POJ 1113 Wall 求凸包的两种方法

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31199   Accepted: 10521 Descriptio ...

  3. 七.生成n位随机字符串

    --1.借助newid() go --创建视图(因为在函数中无法直接使用newid()) create view vnewid as select newid() N'MacoId'; go --创建 ...

  4. JavaScript--模拟验证码

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

  5. 利用iframe实现提交表单是页面部分刷新

    直接上代码: <%@ page language="java" import="java.util.*" pageEncoding="utf-8 ...

  6. POJ3185 The Water Bowls(反转法or dfs 爆搜)

    POJ3185 The Water Bowls 题目大意: 奶牛有20只碗摆成一排,用鼻子顶某只碗的话,包括左右两只在内的一共三只碗会反向,现在给出碗的初始状态,问至少要用鼻子顶多少次才能使所有碗都朝 ...

  7. android 9Path图片的使用

    Android UI设计时,经常会使用图片作为背景,比如给按钮设置背景图片时,图片会默认缩放来适应整个按钮.但是有时这种缩放效果并不是我们所需求的.而我们只是希望缩放图片的特定位置,以此来保证按钮的视 ...

  8. C# FTP操作

    using System; using System.Collections.Generic; using System.Net; using System.IO; namespace FTP操作 { ...

  9. fedora20 播放aiv视频

    环境:fedora20 64位 下载个教程是avi的格式,用FEDORA自带的视频播放提示少插件,搜索又没有.  到网上搜索后,参考下面的方式添加软件仓库后,再打开视频播放顺利装好插件.但视频画件一闪 ...

  10. Swift互用性: 使用Objective-C特性编写Swift类(Swift 2.0版)-b

    本节包括内容: 继承Objective-C的类(Inheriting from Objective-C Classes) 采用协议(Adopting Protocols) 编写构造器和析构器(Writ ...