This commit is contained in:
cheney 2023-08-09 13:57:49 +08:00
parent 300afb65e0
commit dd6405ff4d
111 changed files with 23270 additions and 556 deletions

4
Dockerfile Normal file
View File

@ -0,0 +1,4 @@
FROM registry.cn-hangzhou.aliyuncs.com/fullstack/nginx
MAINTAINER cheney
ADD www /app
ADD default.conf /etc/nginx/conf.d

View File

@ -4,6 +4,8 @@
- 采用 hugo 部署方式,方便高效。 - 采用 hugo 部署方式,方便高效。
- 主要的配置信息都集成到了 config.toml一键完成各种自定义的配置。 - 主要的配置信息都集成到了 config.toml一键完成各种自定义的配置。
- 导航的各个信息都集成在 data/webstack.yml 文件中,方便后续增删改动。 - 导航的各个信息都集成在 data/webstack.yml 文件中,方便后续增删改动。
- 图标存放在目录 static/assets/images/logos, 120 x 120 像素。
``` ```
- taxonomy: 科研办公 - taxonomy: 科研办公
icon: fas fa-flask fa-lg icon: fas fa-flask fa-lg

7
build.cmd Normal file
View File

@ -0,0 +1,7 @@
@REM 自动发布脚本
cd src
hugo
cd ..
xcopy swa www\swa /s /e /y
docker build -t fullstack.web .

11
default.conf Normal file
View File

@ -0,0 +1,11 @@
server {
listen 80;
location / {
root /app;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

14
hex.js
View File

@ -1,14 +0,0 @@
var v = "023030333830303630313233343536373839303132333435363738393031323334353637383930303030303030303030303030303030303030303030303030313233343536373833313230323231313039303030303132333430303030303030303030303030313030313033314303";
var nv = "";
var flag = false
for ( let vv of v ) {
nv += vv;
if ( flag ) {
nv += " "
flag =false
} else {
flag = true
}
}
console.log( nv )

11
kit.json Normal file
View File

@ -0,0 +1,11 @@
{
"publish" : [{
"shell" : "echo \"window.active = 'http://127.0.0.1:8066'\" >> ./dist/config.js"
},{
"shell" : "echo \"window.server = '/api/v1'\" >> ./dist/config.js"
},{
"shell" : "npm run build"
},{
"shell" : "scp -C -v -r www root@n4.fullstack.club:/app/fullstack/"
}]
}

View File

@ -1,8 +1,2 @@
@REM call quasar build docker tag fullstack.web registry.cn-hangzhou.aliyuncs.com/fullstack/fullstack.web
@REM docker push registry.cn-hangzhou.aliyuncs.com/fullstack/fullstack.web
@REM timeout /T 3 /NOBREAK
cd src
hugo
cd ..
xcopy swa www\swa /s /e /y
scp -r www root@n4.fullstack.club:/app/fullstack/

View File

@ -36,4 +36,4 @@ publishDir = "../www"
unsafe = true unsafe = true
[params.footer] [params.footer]
copyright = '本站内容源自互联网如有内容侵犯了你的权益请联系删除相关内容联系邮箱postmaster@fullstack.club <br/>&copy; 2021 - {year} By [FullStack Club](https://www.fullstack.club) | [浙ICP备14009836号-5](http://beian.miit.gov.cn/)<br/>' copyright = '本站内容源自互联网如有内容侵犯了你的权益请联系删除相关内容联系邮箱postmaster@fullstack.club <br/>&copy; 2021 - {year} By [FullStack Club](https://www.fullstack.club) | <a href="http://beian.miit.gov.cn/" target="_blank">浙ICP备14009836号-5</a><br/>'

View File

@ -3,18 +3,14 @@
- taxonomy: 常用推荐 - taxonomy: 常用推荐
icon: far fa-star icon: far fa-star
links: links:
- title: 知乎
logo: 知乎.png
url: https://www.zhihu.com/
description: 知乎社区。
- title: V2EX - title: V2EX
logo: v2ex.jpg logo: v2ex.jpg
url: https://www.v2ex.com/ url: https://www.v2ex.com/
description: V2EX 创意工作者的社区。 description: V2EX 创意工作者的社区。
- title: Hacker News - title: 知乎
url: https://news.ycombinator.com/ logo: 知乎.png
logo: hacker-news.jpg url: https://www.zhihu.com/
description: 一家关于计算机黑客和创业公司的社会化新闻网站 description: 知乎社区
- title: 开源中国 - title: 开源中国
logo: 开源中国.jpg logo: 开源中国.jpg
url: https://www.oschina.net/ url: https://www.oschina.net/
@ -23,28 +19,44 @@
logo: 阿里云.jpg logo: 阿里云.jpg
url: https://www.aliyun.com/ url: https://www.aliyun.com/
description: 上云就上阿里云。 description: 上云就上阿里云。
- title: 七牛云
url: https://sso.qiniu.com/
logo: qiniu.jpg
description: 七牛云。
- taxonomy: 素材资源 - taxonomy: 在线工具
icon: far fa-folder-open fa-lg icon: far fa-folder-open fa-lg
list: list:
- term: 在线工具 - term: 常用工具
links: links:
- title: 目标十字
url: /swa/window.html?to=%2Fswa%2Fcross-nav%2Findex.html
logo: cross.jpg
description: 目标十字
- title: 类型转换
url: /swa/window.html?to=%2Fswa%2Ffmtconv%2Findex.html
logo: ic.png
description: Base64、Hex、UTF8 互相转换
- title: ASN.1 - title: ASN.1
url: /swa/window.html?to=%2Fswa%2Fasn1%2Findex.html url: /swa/window.html?to=%2Fswa%2Fasn1%2Findex.html
logo: duolao.png logo: duolao.png
description: 解析 ASN.1 description: 解析 ASN.1
- title: 无线支付密码器 - title: ASCII 码表
url: /swa/window.html?to=%2Fswa%2Fcpe%2Findex.html url: https://c.runoob.com/front-end/6318/
logo: svgomg.png logo: isux.png
description: 无线支付密码器 description: ASCII 码表
- title: Key 发行器 # - title: 无线支付密码器
url: /swa/window.html?to=%2Fswa%2Fu%2Findex.html # url: /swa/window.html?to=%2Fswa%2Fcpe%2Findex.html
logo: u.png # logo: svgomg.png
description: UKey 发行器 # description: 无线支付密码器
- title: IC 卡发行器 # - title: UKey 发行器
url: /swa/window.html?to=%2Fswa%2Fic%2Findex.html # url: /swa/window.html?to=%2Fswa%2Fu%2Findex.html
logo: ic.png # logo: u.png
description: IC 卡发行器 # description: 渔翁 UKey 发行器
# - title: IC 卡发行器
# url: /swa/window.html?to=%2Fswa%2Fic%2Findex.html
# logo: ic.png
# description: 信雅达 IC 卡发行器
- title: JS Playground - title: JS Playground
url: https://jsfiddle.net/ url: https://jsfiddle.net/
logo: uikitme.png logo: uikitme.png
@ -53,33 +65,38 @@
url: https://tinypng.com/ url: https://tinypng.com/
logo: tinypng.png logo: tinypng.png
description: Optimize your images with a perfect balance in quality and file size. description: Optimize your images with a perfect balance in quality and file size.
- title: goqr - title: AutoRegex
url: http://goqr.me/ logo: Iconfinder.png
logo: goqr.png url: https://www.autoregex.xyz/
description: create QR codes for free (Logo, T-Shirt, vCard, EPS). description: 人工智能辅助正则生成器
- title: ezgif - term: 前端
url: https://ezgif.com links:
logo: ezgif.png - title: Vue
description: simple online GIF maker and toolset for basic animated GIF editing. logo: vue.png
- title: Android 9 patch url: https://cn.vuejs.org/
url: http://inloop.github.io/shadow4android/ description: 渐进式 Javascript 框架。
logo: Android9patch.png - title: Vue Router
description: Android 9-patch shadow generator fully customizable shadows. logo: vue.png
- title: screen sizes url: https://router.vuejs.org/zh/guide/
url: http://screensiz.es/ description: Vue Router 是 Vue.js 的官方路由。
logo: screensizes.png - title: Antd Vue
description: Viewport Sizes and Pixel Densities for Popular Devices. logo: ant.svg
- title: svgomg url: https://www.antdv.com/components/overview-cn/
url: https://jakearchibald.github.io/svgomg/ description: 这里是 Ant Design 的 Vue 实现,开发和服务于企业级后台产品。
logo: svgomg.png - title: Vant
description: SVG 在线压缩平台。 logo: vant4.png
- title: 稿定抠图 url: https://vant-contrib.gitee.io/vant/
url: https://koutu.gaoding.com/ description: 轻量、可定制的移动端 Vue 组件库。
logo: gaoding.png - title: WebPack
description: 免费在线抠图软件,图片快速换背景-抠白底图。 logo: webpack.svg
url: https://webpack.docschina.org/
description: 构建你的 ...
- title: vite
logo: vite.png
url: https://cn.vitejs.dev/
description: 下一代的前端工具链
- term: 图标
- term: 图标素材
links: links:
- title: Iconfinder - title: Iconfinder
logo: Iconfinder.png logo: Iconfinder.png
@ -133,8 +150,6 @@
logo: simplelineicons.png logo: simplelineicons.png
url: http://simplelineicons.com/ url: http://simplelineicons.com/
description: Simple line Icons pack. description: Simple line Icons pack.
- term: 图标设计
links:
- title: Iconsfeed - title: Iconsfeed
logo: iconsfeed.png logo: iconsfeed.png
url: http://www.iconsfeed.com/ url: http://www.iconsfeed.com/
@ -151,7 +166,8 @@
logo: InstantLogoSearch.png logo: InstantLogoSearch.png
url: http://instantlogosearch.com/ url: http://instantlogosearch.com/
description: Search & download thousands of logos instantly. description: Search & download thousands of logos instantly.
- term: 平面素材
- term: 图片处理
links: links:
- title: freepik - title: freepik
logo: freepik.png logo: freepik.png
@ -205,6 +221,27 @@
logo: sccnn.png logo: sccnn.png
url: http://www.sccnn.com/ url: http://www.sccnn.com/
description: 免费素材共享平台。 description: 免费素材共享平台。
- title: goqr
url: http://goqr.me/
logo: goqr.png
description: create QR codes for free (Logo, T-Shirt, vCard, EPS).
- title: ezgif
url: https://ezgif.com
logo: ezgif.png
description: simple online GIF maker and toolset for basic animated GIF editing.
- title: screen sizes
url: http://screensiz.es/
logo: screensizes.png
description: Viewport Sizes and Pixel Densities for Popular Devices.
- title: svgomg
url: https://jakearchibald.github.io/svgomg/
logo: svgomg.png
description: SVG 在线压缩平台。
- title: 稿定抠图
url: https://koutu.gaoding.com/
logo: gaoding.png
description: 免费在线抠图软件,图片快速换背景-抠白底图。
- term: 字体资源 - term: 字体资源
links: links:
- title: Google Font - title: Google Font
@ -267,6 +304,7 @@
url: http://www.abstractfonts.com/ url: http://www.abstractfonts.com/
logo: abstractfonts.png logo: abstractfonts.png
description: Abstract Fonts (13,866 free fonts). description: Abstract Fonts (13,866 free fonts).
- term: PPT资源 - term: PPT资源
links: links:
- title: OfficePLUS - title: OfficePLUS

View File

@ -8,7 +8,7 @@
<meta name="author" content="viggo" /> <meta name="author" content="viggo" />
<title>{{ .Site.Title }}</title> <title>{{ .Site.Title }}</title>
<link rel="shortcut icon" href="../assets/images/favicon.ico"> <link rel="shortcut icon" href="../assets/images/favicon.ico">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Arimo:400,700,400italic"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Arimo:400,700,400italic">
<link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css"> <link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css">
<link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css"> <link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../assets/css/bootstrap.css"> <link rel="stylesheet" href="../assets/css/bootstrap.css">

View File

@ -6,10 +6,8 @@
<div class="s-type-list big"> <div class="s-type-list big">
<div class="anchor" style="position: absolute; left: 50%; opacity: 0;"></div> <div class="anchor" style="position: absolute; left: 50%; opacity: 0;"></div>
<label for="type-bing" class="" data-id="group-a"><span>常用</span></label> <label for="type-bing" class="" data-id="group-a"><span>常用</span></label>
<label for="type-baidu1" data-id="group-b"><span>搜索</span></label>
<label for="type-br" data-id="group-c"><span>工具</span></label> <label for="type-br" data-id="group-c"><span>工具</span></label>
<label for="type-zhihu" data-id="group-d"><span>社区</span></label> <label for="type-zhihu" data-id="group-d"><span>社区</span></label>
<label for="type-taobao1" data-id="group-e"><span>生活</span></label>
</div> </div>
</div> </div>
</div> </div>
@ -37,28 +35,6 @@
<label for="type-pubmed"><span class="text-muted">文献</span></label></li> <label for="type-pubmed"><span class="text-muted">文献</span></label></li>
</ul> </ul>
</div> </div>
<div class="search-group group-b ">
<ul class="search-type">
<li><input hidden="" type="radio" name="type" id="type-baidu1"
value="https://www.baidu.com/s?wd=" data-placeholder="百度一下,你就知道"><label
for="type-baidu1"><span class="text-muted">百度</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-google1"
value="https://www.google.com/search?q=" data-placeholder="谷歌搜索"><label
for="type-google1"><span class="text-muted">谷歌</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-360"
value="https://www.so.com/s?q=" data-placeholder="360 好搜"><label
for="type-360"><span class="text-muted">360</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-sogo"
value="https://www.sogou.com/web?query=" data-placeholder="搜狗搜索"><label
for="type-sogo"><span class="text-muted">搜狗</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-bing1"
value="https://cn.bing.com/search?q=" data-placeholder="微软 Bing 搜索"><label
for="type-bing1"><span class="text-muted">必应</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-sm"
value="https://yz.m.sm.cn/s?q=" data-placeholder="UC 移动端搜索"><label
for="type-sm"><span class="text-muted">神马</span></label></li>
</ul>
</div>
<div class="search-group group-c "> <div class="search-group group-c ">
<ul class="search-type"> <ul class="search-type">
<li><input hidden="" type="radio" name="type" id="type-br" <li><input hidden="" type="radio" name="type" id="type-br"
@ -95,22 +71,6 @@
<label for="type-douban"><span class="text-muted">豆瓣</span></label></li> <label for="type-douban"><span class="text-muted">豆瓣</span></label></li>
</ul> </ul>
</div> </div>
<div class="search-group group-e ">
<ul class="search-type">
<li><input hidden="" type="radio" name="type" id="type-taobao1" value="https://s.taobao.com/search?q=" data-placeholder="淘宝">
<label for="type-taobao1"><span class="text-muted">淘宝</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-jd" value="https://search.jd.com/Search?keyword=" data-placeholder="京东">
<label for="type-jd"><span class="text-muted">京东</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-xiachufang" value="https://www.xiachufang.com/search/?keyword=" data-placeholder="下厨房">
<label for="type-xiachufang"><span class="text-muted">下厨房</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-xiangha" value="https://www.xiangha.com/so/?q=caipu&s=" data-placeholder="香哈菜谱">
<label for="type-xiangha"><span class="text-muted">香哈菜谱</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-12306" value="https://www.12306.cn/?" data-placeholder="12306">
<label for="type-12306"><span class="text-muted">12306</span></label></li>
<li><input hidden="" type="radio" name="type" id="type-qunar" value="https://www.qunar.com/?" data-placeholder="去哪儿">
<label for="type-qunar"><span class="text-muted">去哪儿</span></label></li>
</ul>
</div>
</div> </div>
<div class="card search-smart-tips search-hot-text"> <div class="card search-smart-tips search-hot-text">
<ul id="word" style="display: none"></ul> <ul id="word" style="display: none"></ul>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="128px" height="128px" viewBox="0 0 128 128" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 52.6 (67491) - http://www.bohemiancoding.com/sketch -->
<title>Vue</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="69.644116%" y1="0%" x2="69.644116%" y2="100%" id="linearGradient-1">
<stop stop-color="#29CDFF" offset="0%"></stop>
<stop stop-color="#148EFF" offset="37.8600687%"></stop>
<stop stop-color="#0A60FF" offset="100%"></stop>
</linearGradient>
<linearGradient x1="-19.8191553%" y1="-36.7931464%" x2="138.57919%" y2="157.637507%" id="linearGradient-2">
<stop stop-color="#29CDFF" offset="0%"></stop>
<stop stop-color="#0F78FF" offset="100%"></stop>
</linearGradient>
<linearGradient x1="68.1279872%" y1="-35.6905737%" x2="30.4400914%" y2="114.942679%" id="linearGradient-3">
<stop stop-color="#FA8E7D" offset="0%"></stop>
<stop stop-color="#F74A5C" offset="51.2635191%"></stop>
<stop stop-color="#F51D2C" offset="100%"></stop>
</linearGradient>
</defs>
<g id="Vue" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Group" transform="translate(19.000000, 9.000000)">
<path d="M89.96,90.48 C78.58,93.48 68.33,83.36 67.62,82.48 L46.6604487,62.2292258 C45.5023849,61.1103236 44.8426845,59.5728835 44.8296987,57.9626396 L44.5035564,17.5209948 C44.4948861,16.4458744 44.0537714,15.4195095 43.2796864,14.6733517 L29.6459999,1.53153737 C28.055475,-0.00160504005 25.5232423,0.0449126588 23.9900999,1.63543756 C23.2715121,2.38092066 22.87,3.37600834 22.87,4.41143746 L22.87,64.3864751 C22.87,67.0807891 23.9572233,69.6611067 25.885409,71.5429748 L63.6004615,108.352061 C65.9466323,110.641873 69.6963584,110.624605 72.0213403,108.313281" id="Path-Copy" fill="url(#linearGradient-1)" fill-rule="nonzero" transform="translate(56.415000, 54.831157) scale(-1, 1) translate(-56.415000, -54.831157) "></path>
<path d="M68,90.1163122 C56.62,93.1163122 45.46,83.36 44.75,82.48 L23.7904487,62.2292258 C22.6323849,61.1103236 21.9726845,59.5728835 21.9596987,57.9626396 L21.6335564,17.5209948 C21.6248861,16.4458744 21.1837714,15.4195095 20.4096864,14.6733517 L6.7759999,1.53153737 C5.185475,-0.00160504005 2.65324232,0.0449126588 1.12009991,1.63543756 C0.401512125,2.38092066 3.90211878e-13,3.37600834 3.90798505e-13,4.41143746 L3.94351218e-13,64.3864751 C3.94681177e-13,67.0807891 1.08722326,69.6611067 3.01540903,71.5429748 L40.7807092,108.401101 C43.1069304,110.671444 46.8180151,110.676525 49.1504445,108.412561" id="Path" fill="url(#linearGradient-2)" fill-rule="nonzero"></path>
<path d="M43.2983488,19.0991931 L27.5566079,3.88246244 C26.7624281,3.11476967 26.7409561,1.84862177 27.5086488,1.05444194 C27.8854826,0.664606611 28.4044438,0.444472651 28.9466386,0.444472651 L60.3925021,0.444472651 C61.4970716,0.444472651 62.3925021,1.33990315 62.3925021,2.44447265 C62.3925021,2.9858375 62.1730396,3.50407742 61.7842512,3.88079942 L46.0801285,19.0975301 C45.3051579,19.8484488 44.0742167,19.8491847 43.2983488,19.0991931 Z" id="Path" fill="url(#linearGradient-3)"></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -0,0 +1 @@
<svg viewBox="0 0 600 600" xmlns="http://www.w3.org/2000/svg"><path d="m300 .1 265 149.9v299.9l-265 149.9-265-149.9v-299.9z" fill="#fff"/><path d="m517.7 439.5-208.9 118.3v-92l130.2-71.7zm14.3-12.9v-247.2l-76.4 44.1v159zm-450.5 12.9 208.9 118.2v-92l-130.2-71.6zm-14.3-12.9v-247.2l76.4 44.1v159zm8.9-263.2 214.3-121.2v89l-137.3 75.5-1.1.6zm446.9 0-214.2-121.2v89l137.2 75.6 1.1.6z" fill="#8ed6fb"/><path d="m290.4 444.8-128.4-70.7v-139.9l128.4 74.1zm18.4 0 128.4-70.6v-140l-128.4 74.1zm-138.2-226.8 129-70.9 128.9 70.9-128.9 74.4z" fill="#1c78c0"/></svg>

After

Width:  |  Height:  |  Size: 553 B

8
start.sh Normal file
View File

@ -0,0 +1,8 @@
img=registry.cn-hangzhou.aliyuncs.com/fullstack/fullstack.web
name=fullstack.web
docker pull $img
docker rm -vf $name
docker run -d --restart always \
--name $name \
-p 8081:80 \
$img

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en-US,zh-CN">
<head> <head>
<meta charset="US-ASCII"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ASN.1 JavaScript decoder</title> <title>ASN.1 JavaScript decoder</title>
<link rel="stylesheet" href="index.css" type="text/css"> <link rel="stylesheet" href="index.css" type="text/css">
@ -15,12 +15,12 @@
<form> <form>
<textarea id="area" style="width: 100%;" rows="8"></textarea> <textarea id="area" style="width: 100%;" rows="8"></textarea>
<br> <br>
<label title="can be slow with big files"><input type="checkbox" id="wantHex" checked="checked"> with hex dump</label> <label title="can be slow with big files"><input type="checkbox" id="wantHex" checked="checked">显示 HEX DUMP</label>
<input id="butDecode" type="button" value="decode"> <input id="butDecode" type="button" value="解码">
<input id="butClear" type="button" value="clear"> <input id="butClear" type="button" value="清空">
<input type="file" id="file"> <input type="file" id="file">
<div> <div>
Examples: 示例:
<select id="examples"> <select id="examples">
<option value="sig-p256-der.p7m">PKCS#7/CMS attached signature (DER)</option> <option value="sig-p256-der.p7m">PKCS#7/CMS attached signature (DER)</option>
<option value="sig-p256-ber.p7m">PKCS#7/CMS attached signature (BER)</option> <option value="sig-p256-ber.p7m">PKCS#7/CMS attached signature (BER)</option>
@ -28,7 +28,7 @@
<option value="letsencrypt-x3.cer">X.509 certificate: Let's Encrypt X3</option> <option value="letsencrypt-x3.cer">X.509 certificate: Let's Encrypt X3</option>
<option value="ed25519.cer">X.509 certificate: ed25519 (RFC 8410)</option> <option value="ed25519.cer">X.509 certificate: ed25519 (RFC 8410)</option>
</select> </select>
<input id="butExample" type="button" value="load example"> <input id="butExample" type="button" value="载入示例">
</div> </div>
</form> </form>
@ -39,5 +39,45 @@
<script type="text/javascript" src="asn1.js"></script> <script type="text/javascript" src="asn1.js"></script>
<script type="text/javascript" src="dom.js"></script> <script type="text/javascript" src="dom.js"></script>
<script type="text/javascript" src="index.js"></script> <script type="text/javascript" src="index.js"></script>
<script type="application/javascript" src="./jquery-1.8.0.min.js"></script>
<script type="application/javascript">
$(function (){
$(document).keydown(function(event) {
if (event.ctrlKey && event.which == 67) {
console.log("Ctrl + C 被按下");
event.preventDefault(); // 阻止默认的复制操作
// 寻找激活的 node
$(".node:hover").each(function() {
var $this = $(this)
if ( $this.hasClass("node") && $this.hasClass("collapsed") ) {
console.log("当前 hover 的标签:", this);
let $b = $this.find("b")[0]
if ( $b ) {
var v = $($b).text()
console.log("v=" , v)
navigator.clipboard.writeText(v)
.then(function() {
console.log('内容已复制到剪贴板');
// 可选:清除输入框内容
tempInput.remove();
})
.catch(function(err) {
console.error('无法写入剪贴板:', err);
// 可选:清除输入框内容
tempInput.remove();
});
}
}
});
}
});
})
</script>
</body> </body>
</html> </html>

2
swa/asn1/jquery-1.8.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

1
swa/cross-nav/PIXI.TextInput.min.js vendored Normal file

File diff suppressed because one or more lines are too long

17
swa/cross-nav/color.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
background: #CC0000;
background: #EE0000;
}
</style>
</head>
<body>
</body>
</html>

View File

@ -61,6 +61,18 @@
<button type="button" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" data-html="true" <button type="button" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" data-html="true"
title="</br><ol><li>点击【添加】画板中会添加一个默认事件</li><li>右键事件可以修改</li><li>将事件修改为空会完全删除事件</li><li>刷新页面会丢失所有数据</li></ol>">帮助</button> title="</br><ol><li>点击【添加】画板中会添加一个默认事件</li><li>右键事件可以修改</li><li>将事件修改为空会完全删除事件</li><li>刷新页面会丢失所有数据</li></ol>">帮助</button>
<div class="dropdown" style="display: inline-block">
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
选色 <div id="color" style="display: inline-block; width: 0.8rem; height: 0.8rem; background: red">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" onclick="setColor(0xFF0000)"><div style="display: inline-block; width: 20px; height: 0.8rem; background: red"></div></a>
<a class="dropdown-item" href="#" onclick="setColor(0xFFBB00)"><div style="display: inline-block; width: 20px; height: 0.8rem; background: orange"></div></a>
<a class="dropdown-item" href="#" onclick="setColor(0x009FCC)"><div style="display: inline-block; width: 20px; height: 0.8rem; background: blue"></div></a>
<a class="dropdown-item" href="#" onclick="setColor(0x00FF00)">绿 <div style="display: inline-block; width: 20px; height: 0.8rem; background: green"></div></a>
</div>
</div>
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button onclick="imports()" type="button" class="btn btn-primary"><span class="iconfont">&#xe608;</span>导入 <button onclick="imports()" type="button" class="btn btn-primary"><span class="iconfont">&#xe608;</span>导入
<input style="display: none" type="file" accept=".crossnav.png" class="custom-file-input" id="custom-file-input"> <input style="display: none" type="file" accept=".crossnav.png" class="custom-file-input" id="custom-file-input">
@ -83,10 +95,10 @@
<script src="./bootstrap.bundle.min.js" crossorigin="anonymous"></script> <script src="./bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<!-- 动画库 --> <!-- 动画库 -->
<script src="../../js/pixi.min.js"></script> <script src="./pixi.min.js"></script>
<script src="../../js/PIXI.TextInput.min.js"></script> <script src="./PIXI.TextInput.min.js"></script>
<script src="../../js/png.bundle.js"></script> <script src="./png.bundle.js"></script>
<script type="application/javascript"> <script type="application/javascript">
document.oncontextmenu = function(e){ document.oncontextmenu = function(e){
@ -103,6 +115,19 @@
</script> </script>
<script type="application/javascript"> <script type="application/javascript">
function setColor( c ){
color = c;
var hex = c.toString(16);
if( hex.length < 6 ) {
hex = "000000" + hex
hex = hex.substr( hex.length -6 );
}
$("#color").css({ background : "#" + hex })
}
var color = 0xFF0000 ;
var border = 20; var border = 20;
var size = 512 + 2 * border; // 10 的边框 var size = 512 + 2 * border; // 10 的边框
//Create a Pixi Application //Create a Pixi Application
@ -186,17 +211,19 @@
bg.addChild(message); bg.addChild(message);
} }
var objStyle = new PIXI.TextStyle({
fontFamily: "Arial",
fontSize: 18,
fill: 0x9966FF,
});
var objs = new PIXI.Container(); var objs = new PIXI.Container();
app.stage.addChild(objs); app.stage.addChild(objs);
function newObj(x, y, name){ function newObj(x, y, name, c){
var objStyle = new PIXI.TextStyle({
fontFamily: "Arial",
fontSize: 18,
fill: c || color,
});
var obj = new PIXI.Container(); var obj = new PIXI.Container();
obj.backgroundColor = 0x1099bb; obj.backgroundColor = 0x1099bb;
@ -206,7 +233,7 @@
// point // point
var circle = new PIXI.Graphics(); var circle = new PIXI.Graphics();
circle.beginFill(0x9966FF); circle.beginFill( c || color );
circle.drawCircle( 0, 0, 5 ); circle.drawCircle( 0, 0, 5 );
circle.endFill(); circle.endFill();
circle.position.set(0 , 0 ); circle.position.set(0 , 0 );
@ -226,7 +253,7 @@
} }
}) })
input.position.set(0 + 8 , 0 - 10); input.position.set(0 + 8 , 0 - 10);
input.placeholder = 'Enter your Text...' input.placeholder = '输入...'
input.visible = false input.visible = false
input.maxLength = 20 input.maxLength = 20
input.on('keydown', function (keycode) { input.on('keydown', function (keycode) {
@ -239,13 +266,15 @@
console.log( "blur" ) console.log( "blur" )
endEdit() endEdit()
}) })
function endEdit(){ function endEdit(){
input.visible = false input.visible = false
message.visible = true message.visible = true
if ( input.text ) { if ( input.text ) {
message.text = input.text message.text = input.text
} else { } else {
app.stage.removeChild(obj); objs.removeChild(obj);
} }
} }
@ -330,7 +359,7 @@
var json = meta.crossnav var json = meta.crossnav
json = JSON.parse( json ) json = JSON.parse( json )
json.map(function (a){ json.map(function (a){
newObj(a.x, a.y, a.text) newObj(a.x, a.y, a.text, a.color)
}) })
}catch ( e ) { }catch ( e ) {
@ -351,10 +380,14 @@
let info = [] let info = []
for (let c of objs.children) { for (let c of objs.children) {
var t = c.getChildByName('message')
info.push({ info.push({
x : c.x, x : c.x,
y : c.y, y : c.y,
text : c.getChildByName('message').text text : t.text,
color : t.style.fill
}) })
} }

8
swa/cross-nav/pixi.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2491
swa/cross-nav/png.bundle.js Normal file

File diff suppressed because it is too large Load Diff

143
swa/fmtconv/index.html Normal file
View File

@ -0,0 +1,143 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>格式转换</title>
<style>
body {
text-align: center;
margin-top: 100px;
}
.io {
width: 80%;
display: inline-block;
height : 5rem
}
.turn {
margin: 2rem;
}
button-group {
display: inline-block;
margin: 0 0.5rem;
/*width: 1rem;*/
}
button-group button {
display: block;
}
</style>
</head>
<body>
<h3>输入</h3>
<textarea id="in" class="io"></textarea>
<div class="turn">
<button-group>
<button id="turnio" style="margin-right: 5rem; ">交换输入输出</button>
<button id="clearo" style="margin-right: 5rem; ">&emsp;清空输出&emsp;</button>
<button id="clear" style="margin-right: 5rem; ">&emsp;清空所有&emsp;</button>
</button-group>
<button-group>
<button id="utf8Tobase64">UTF8 转 base64</button>
<br>
<button id="base64ToUtf8">base64 转 UTF8</button>
</button-group>
<button-group>
<button id="base64ToHex">base64 转 Hex</button>
<br>
<button id="hexToBase64">Hex 转 base64</button>
</button-group>
<button-group>
<button id="utf8ToHex">UTF8 转 Hex</button>
<br>
<button id="hexToUtf8">Hex 转 UTF8</button>
</button-group>
</div>
<h3>输出</h3>
<textarea id="out" class="io"></textarea>
<!--<script type="application/javascript" src="base64.js"></script>-->
<script type="application/javascript" src="tool.js"></script>
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="application/javascript">
$(function () {
$("#turnio").click(function () {
var inText = $("#in").val();
var outText = $("#out").val();
$("#in").val( outText );
$("#out").val( inText );
})
$("#cleari").click(function () {
$("#in").val("");
})
$("#clearo").click(function () {
$("#out").val("");
})
$("#clear").click(function () {
$("#in").val("");
$("#out").val("");
})
$("#utf8Tobase64").click(function () {
var inText = $("#in").val();
var out = utf8ToBase64( inText );
$("#out").val( out );
})
$("#base64ToUtf8").click(function () {
var inText = $("#in").val();
var out = base64ToUtf8(inText)
$("#out").val( out );
})
$("#base64ToHex").click(function () {
var inText = $("#in").val();
var out = base64ToHex(inText)
$("#out").val( out );
})
$("#hexToBase64").click(function () {
var inText = $("#in").val();
var out = hexToBase64( inText )
$("#out").val( out );
})
$("#hexToUtf8").click(function () {
var inText = $("#in").val();
out = hexToUtf8(inText)
$("#out").val( out );
})
$("#utf8ToHex").click(function () {
var inText = $("#in").val();
out = utf8ToHex( inText )
$("#out").val( out );
})
})
</script>
</body>
</html>

4
swa/fmtconv/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

37
swa/fmtconv/test.js Normal file
View File

@ -0,0 +1,37 @@
const tool = require("./tool")
const str1 = "722 黄谦 cheney";
const str2 = "MIIBygYJKoZIhvcNAQcDoIIBuzCCAbcCAQAxggFLMIIBRwIBADAvMCMxCzAJBgNVBAYTAmNuMRQwEgYDVQQKEwtQQkMgVEVTVCBDQQIIE6NthajbntAwDQYJKoZIhvcNAQEBBQAEggEAfpqiXGzxULaCOJIPqRKFAsk/21WIg+NnrkgP/18OxSr68vnpLXKB2aDsyntX9RkwDVc/VwD7nrAq9l0xZPndrYQS2h8ayFfFUan7L5MtOvxS4Pt5+o84DE00+3axfkAr2v7I79tWFmAc0sipn+nQcJzoy0owknfG41hMauMrPI9jdtb1ZcUWLH0bMQ3VeYJJi8RSFYqirpc+RM3sOqwIvBthDcMdnH4XoUx4FKSdnpUd5wHd8Q1cEleVA1PAuEtim2ivjJ8450Y/08pURDOWcmabvX/f4mMp9437uigaC4qShRilyX3/Dt3xhdjq6ImKGxwLUqAaIM6DtHub08S0OTBjBgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECP6Q/L2a03NMgECXtfqTp+J8JJGL9mNjf51jMe+C4E02q6UQtImLqmvnBEXCnkDLKOBIvOO7ADrlRDN73cma0865Qp1QXP2PT7ez"
const hex2 = "308201ca06092a864886f70d010703a08201bb308201b70201003182014b30820147020100302f3023310b300906035504061302636e31143012060355040a130b5042432054455354204341020813a36d85a8db9ed0300d06092a864886f70d0101010500048201007e9aa25c6cf150b68238920fa9128502c93fdb558883e367ae480fff5f0ec52afaf2f9e92d7281d9a0ecca7b57f519300d573f5700fb9eb02af65d3164f9ddad8412da1f1ac857c551a9fb2f932d3afc52e0fb79fa8f380c4d34fb76b17e402bdafec8efdb5616601cd2c8a99fe9d0709ce8cb4a309277c6e3584c6ae32b3c8f6376d6f565c5162c7d1b310dd57982498bc452158aa2ae973e44cdec3aac08bc1b610dc31d9c7e17a14c7814a49d9e951de701ddf10d5c1257950353c0b84b629b68af8c9f38e7463fd3ca5444339672669bbd7fdfe26329f78dfbba281a0b8a928518a5c97dff0eddf185d8eae8898a1b1c0b52a01a20ce83b47b9bd3c4b439306306092a864886f70d010701301406082a864886f70d03070408fe90fcbd9ad3734c804097b5fa93a7e27c24918bf663637f9d6331ef82e04d36aba510b4898baa6be70445c29e40cb28e048bce3bb003ae544337bddc99ad3ceb9429d505cfd8f4fb7b3"
const str3 = "722 cheney";
const ret2 = tool.base64ToHex( str2 )
console.log("hex=" + ret2)
console.assert( ret2 === hex2, "base64ToHex 转换失败" );
const ret22 = tool.hexToBase64( ret2 )
console.assert( str2 === ret22, "base64 hex 转换失败" );
const base64 = tool.utf8ToBase64(str1)
const ret3 = tool.base64ToHex( base64 )
console.log("base64ToHex hex=" + ret3 )
const ret32 = tool.hexToBase64( ret3 )
console.assert( ret32 === base64, "base64 hex 中文 转换失败" );
var ret11 = tool.utf8ToBase64(str1)
console.log("hex=" + ret11 )
var ret12 = tool.base64ToUtf8(ret11)
console.log("ret12=" + ret12)
console.assert( str1 === ret12, "base64 String 中文转换失败" );
var ret4 = tool.utf8ToHex(str1);
var ret41 = tool.hexToUtf8(ret4);
console.assert( str1 === ret41, "hex String 中文转换失败" );

551
swa/fmtconv/tool.js Normal file
View File

@ -0,0 +1,551 @@
var codePoint2utf8 = function (code) {
var bin = parseInt(code).toString(2)
var ln = 0;
var mx = 0;
if (bin.length <= 7) {
ln = 1;
mx = 7;
} else if (bin.length > 7 && bin.length <= 11) {
ln = 2;
mx = 11;
} else if (bin.length > 11 && bin.length <= 16) {
ln = 3;
mx = 16;
} else if (bin.length > 16 && bin.length <= 21) {
ln = 4;
mx = 21;
} else if (bin.length > 21 && bin.length <= 26) {
ln = 5;
mx = 26;
} else if (bin.length > 26 && bin.length <= 31) {
ln = 6;
mx = 31;
};
var longbin = ("0".repeat(mx) + bin).slice(-mx)
var result = '';
for (var i = 0; i < ln; i++) {
if (ln != 1) {
if (i == 0) {
result += parseInt("1".repeat(ln) + "0" + longbin.slice(0,7-ln),2).toString(16);
longbin = longbin.slice(7-ln);
} else {
result += parseInt("10" + longbin.slice(0,6),2).toString(16);
longbin = longbin.slice(6);
};
} else {
result += ("00" + parseInt(longbin,2).toString(16)).slice(-2);
};
};
return result;
};
var stringToHex = function (inputstring) {
var result = '';
for (var i = 0; i < inputstring.length; i++) {
result += codePoint2utf8(inputstring.codePointAt(i))
};
return result;
};
var hexToString = function (inputstring) {
try {
var result = decodeURIComponent(inputstring.toLowerCase().replace(/\s+/g, '').replace(/[0-9a-f]{2}/g, '%$&'));
} catch(e) {
throw "Not valid UTF-8 hex code!";
};
return result;
};
function stringToByte(str) {
var bytes = new Array();
var len, c;
len = str.length;
for(var i = 0; i < len; i++) {
c = str.charCodeAt(i);
if(c >= 0x010000 && c <= 0x10FFFF) {
bytes.push(((c >> 18) & 0x07) | 0xF0);
bytes.push(((c >> 12) & 0x3F) | 0x80);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if(c >= 0x000800 && c <= 0x00FFFF) {
bytes.push(((c >> 12) & 0x0F) | 0xE0);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if(c >= 0x000080 && c <= 0x0007FF) {
bytes.push(((c >> 6) & 0x1F) | 0xC0);
bytes.push((c & 0x3F) | 0x80);
} else {
bytes.push(c & 0xFF);
}
}
return bytes;
}
// utf8
function byteToString(arr) {
if(typeof arr === 'string') {
return arr;
}
var str = '',
_arr = arr;
for(var i = 0; i < _arr.length; i++) {
var one = _arr[i].toString(2),
v = one.match(/^1+?(?=0)/);
if(v && one.length == 8) {
var bytesLength = v[0].length;
var store = _arr[i].toString(2).slice(7 - bytesLength);
for(var st = 1; st < bytesLength; st++) {
store += _arr[st + i].toString(2).slice(2);
}
str += String.fromCharCode(parseInt(store, 2));
i += bytesLength - 1;
} else {
str += String.fromCharCode(_arr[i]);
}
}
return str;
}
/**
* Convert the given string to byte array
*
* @param {string} str the string to be converted to byte array
* @returns {number[]}
*/
var str2bytes = function (str) {
var i = 0;
var ch = null;
var hex = null;
var encoded = encodeURIComponent(str);
var length = encoded.length;
var bytes = [];
while (i < length) {
ch = encoded.charAt(i++);
if (ch === '%') {
hex = encoded.charAt(i++)
hex += encoded.charAt(i++);
bytes.push(parseInt(hex, 16));
} else {
bytes.push(ch.charCodeAt(0));
}
}
return bytes;
};
/**
* Convert the given byte array to string
*
* @param {number[]} bytes The byte array to be converted to string
* @returns {string}
*/
var bytes2str = function (bytes) {
var i = 0;
var hex = null;
var byte = 0;
var hexArray = [];
var length = bytes.length;
while (i < length) {
byte = bytes[i++];
hex = byte.toString(16);
hex = hex.length < 2 ? ('%0' + hex) : ('%' + hex);
hexArray.push(hex);
}
return decodeURIComponent(hexArray.join(''));
};
function base64ArrayBuffer(arrayBuffer) {
var base64 = ''
var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
var bytes = new Uint8Array(arrayBuffer)
var byteLength = bytes.byteLength
var byteRemainder = byteLength % 3
var mainLength = byteLength - byteRemainder
var a, b, c, d
var chunk
// Main loop deals with bytes in chunks of 3
for (var i = 0; i < mainLength; i = i + 3) {
// Combine the three bytes into a single integer
chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
// Use bitmasks to extract 6-bit segments from the triplet
a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12
c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6
d = chunk & 63 // 63 = 2^6 - 1
// Convert the raw binary segments to the appropriate ASCII encoding
base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
}
// Deal with the remaining bytes and padding
if (byteRemainder == 1) {
chunk = bytes[mainLength]
a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
// Set the 4 least significant bits to zero
b = (chunk & 3) << 4 // 3 = 2^2 - 1
base64 += encodings[a] + encodings[b] + '=='
} else if (byteRemainder == 2) {
chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4
// Set the 2 least significant bits to zero
c = (chunk & 15) << 2 // 15 = 2^4 - 1
base64 += encodings[a] + encodings[b] + encodings[c] + '='
}
return base64
}
(function() {
var base64EncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
base64DecodeChars = new Array(( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), 62, ( - 1), ( - 1), ( - 1), 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, ( - 1), ( - 1), ( - 1), ( - 1), ( - 1));
this.base64encode = function(e) {
var r, a, c, h, o, t;
for (c = e.length, a = 0, r = ''; a < c;) {
if (h = 255 & e.charCodeAt(a++), a == c) {
r += base64EncodeChars.charAt(h >> 2),
r += base64EncodeChars.charAt((3 & h) << 4),
r += '==';
break
}
if (o = e.charCodeAt(a++), a == c) {
r += base64EncodeChars.charAt(h >> 2),
r += base64EncodeChars.charAt((3 & h) << 4 | (240 & o) >> 4),
r += base64EncodeChars.charAt((15 & o) << 2),
r += '=';
break
}
t = e.charCodeAt(a++),
r += base64EncodeChars.charAt(h >> 2),
r += base64EncodeChars.charAt((3 & h) << 4 | (240 & o) >> 4),
r += base64EncodeChars.charAt((15 & o) << 2 | (192 & t) >> 6),
r += base64EncodeChars.charAt(63 & t)
}
return r
}
this.base64decode = function(e) {
var r, a, c, h, o, t, d;
for (t = e.length, o = 0, d = ''; o < t;) {
do r = base64DecodeChars[255 & e.charCodeAt(o++)];
while (o < t && r == -1);
if (r == -1) break;
do a = base64DecodeChars[255 & e.charCodeAt(o++)];
while (o < t && a == -1);
if (a == -1) break;
d += String.fromCharCode(r << 2 | (48 & a) >> 4);
do {
if (c = 255 & e.charCodeAt(o++), 61 == c) return d;
c = base64DecodeChars[c]
} while ( o < t && c == - 1 );
if (c == -1) break;
d += String.fromCharCode((15 & a) << 4 | (60 & c) >> 2);
do {
if (h = 255 & e.charCodeAt(o++), 61 == h) return d;
h = base64DecodeChars[h]
} while ( o < t && h == - 1 );
if (h == -1) break;
d += String.fromCharCode((3 & c) << 6 | h)
}
return d
}
this.HexToBase64 = function(str) {
return base64encode(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
}
this.Base64Tohex = function(str) {
for (var i = 0,
bin = base64decode(str.replace(/[ \r\n]+$/, "")), hex = []; i < bin.length; ++i) {
var tmp = bin.charCodeAt(i).toString(16);
if (tmp.length === 1) tmp = "0" + tmp;
hex[hex.length] = tmp;
}
return hex.join("");
},
this.toBytes = function(str) {
for (var bytes = [], c = 0; c < str.length; c += 2)
bytes.push(parseInt(str.substr(c, 2), 16));
return bytes;
}
}) ();
//hexToBase64 Base64Tohex base64decode base64encode
var bytesToString = function(bytes){
return hexToString(bytesToHex(bytes));
}
var bytesToBase64 = function(bytes){
return base64ArrayBuffer(bytes);
}
// Convert a byte array to a hex string
var bytesToHex = function(bytes) {
for (var hex = [], i = 0; i < bytes.length; i++) {
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join("");
}
var stringToBase64 = function(str){
return base64encode(str);
}
var stringToBytes = function(str){
return hexToBytes(stringToHex(str));
}
// Convert a ASCII string to a hex string
var stringToHex = function(str) {
return str.split("").map(function(c) {
return ("0" + c.charCodeAt(0).toString(16)).slice(-2);
}).join("");
}
var hexToBytes= function(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
// Convert a hex string to a ASCII string
var hexToString = function(hexStr) {
var hex = hexStr.toString();//force conversion
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
var hexToBase64 = function(hexStr){
return HexToBase64(hexStr);
}
var base64ToString = function(base64str){
return base64decode(base64str);
}
const Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
i = e.charCodeAt(f++);
s = n >> 2;
o = (n & 3) << 4 | r >> 4;
u = (r & 15) << 2 | i >> 6;
a = i & 63;
if (isNaN(r)) {
u = a = 64
} else if (isNaN(i)) {
a = 64
}
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
}
return t
},
decode: function(e) {
var t = "";
var n, r, i;
var s, o, u, a;
var f = 0;
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
while (f < e.length) {
s = this._keyStr.indexOf(e.charAt(f++));
o = this._keyStr.indexOf(e.charAt(f++));
u = this._keyStr.indexOf(e.charAt(f++));
a = this._keyStr.indexOf(e.charAt(f++));
n = s << 2 | o >> 4;
r = (o & 15) << 4 | u >> 2;
i = (u & 3) << 6 | a;
t = t + String.fromCharCode(n);
if (u != 64) {
t = t + String.fromCharCode(r)
}
if (a != 64) {
t = t + String.fromCharCode(i)
}
}
t = Base64._utf8_decode(t);
return t
},
_utf8_encode: function(e) {
e = e.replace(/rn/g, "n");
var t = "";
for (var n = 0; n < e.length; n++) {
var r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r)
} else if (r > 127 && r < 2048) {
t += String.fromCharCode(r >> 6 | 192);
t += String.fromCharCode(r & 63 | 128)
} else {
t += String.fromCharCode(r >> 12 | 224);
t += String.fromCharCode(r >> 6 & 63 | 128);
t += String.fromCharCode(r & 63 | 128)
}
}
return t
},
_utf8_decode: function(e) {
var t = "";
var n = 0;
var r = 0;
var c1 =0;
var c2 =0;
var c3 =0;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2
} else {
c2 = e.charCodeAt(n + 1);
c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3
}
}
return t
}
}
function encodeUtf8(text) {
const code = encodeURIComponent(text);
const bytes = [];
for (var i = 0; i < code.length; i++) {
const c = code.charAt(i);
if (c === '%') {
const hex = code.charAt(i + 1) + code.charAt(i + 2);
const hexVal = parseInt(hex, 16);
bytes.push(hexVal);
i += 2;
} else bytes.push(c.charCodeAt(0));
}
return bytes;
}
function decodeUtf8(bytes) {
var encoded = "";
for (var i = 0; i < bytes.length; i++) {
encoded += '%' + bytes[i].toString(16);
}
return decodeURIComponent(encoded);
}
function strToBytesUTF8(str) {
let utf8 = [];
for (let i = 0; i < str.length; i++) {
let charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
else if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
// surrogate pair
else {
i++;
// UTF-16 encodes 0x10000-0x10FFFF by
// subtracting 0x10000 and splitting the
// 20 bits of 0x0-0xFFFFF into two halves
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
| (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >>18),
0x80 | ((charcode>>12) & 0x3f),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
}
return utf8;
}
function utf8ToBase64(str){
var ret11 = strToBytesUTF8( str )
return bytesToBase64( ret11 )
}
function base64ToUtf8( str ){
var hex = base64ToHex( str );
var ret = hexToBytes( hex )
// var ret = base64ToBytes( str )
return decodeUtf8(ret);
}
var base64ToHex = function(base64str){
return Base64Tohex(base64str);
}
var base64ToBytes = function(base64str){
return toBytes(base64str);
//null
}
var utf8ToHex = function (str) {
var ret11 = strToBytesUTF8( str )
return bytesToHex( ret11 )
}
var hexToUtf8 = function (hex) {
var ret = hexToBytes( hex )
// var ret = base64ToBytes( str )
return decodeUtf8(ret);
}
if ( module ) {
module.exports = {
stringToByte,
byteToString,
str2bytes,
bytes2str,
base64ArrayBuffer,
bytesToString,
bytesToBase64,
bytesToHex,
stringToBase64,
stringToBytes,
stringToHex,
hexToBytes,
hexToString,
hexToBase64,
base64ToString,
base64ToHex,
base64ToBytes,
Base64,
encodeUtf8,
decodeUtf8,
strToBytesUTF8,
utf8ToBase64,
base64ToUtf8,
utf8ToHex,
hexToUtf8
}
}

View File

@ -366,12 +366,30 @@
} }
var path2 = $("#path2").val(); var path2 = $("#path2").val();
check(path2, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串填充错误") check(path2, /^([A-Fa-f0-9][A-Fa-f0-9]){4}$/g, "特征字串2填充错误")
var path3 = $("#path3").val();
check(path3, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串3填充错误")
var path4 = $("#path4").val();
check(path4, /^([A-Fa-f0-9][A-Fa-f0-9]){4}$/g, "特征字串4填充错误")
var path5 = $("#path5").val();
check(path5, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串5填充错误")
ic.writeHex(0x20, path1) ic.writeHex(0x20, path1)
.then(function (def){ .then(function (def){
return ic.writeHex(0x30, path2) return ic.writeHex(0x30, path2)
}) })
.then(function (def){
return ic.writeHex(0x40, path3)
})
.then(function (def){
return ic.writeHex(0x50, path4)
})
.then(function (def){
return ic.writeHex(0x60, path5)
})
.then(function (def){ .then(function (def){
success("写入成功") success("写入成功")
}) })

View File

@ -83,22 +83,24 @@ function bytesToHex(bytes) {
const DES = require('./jssrc/des.js') // const DES = require('./jssrc/des.js')
var des = new DES(); // var des = new DES();
var key = hexToBytes("12345678123456781234567812345678") // var key = hexToBytes("12345678123456781234567812345678")
var ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key); // var ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
console.log( ret )
des = new DES();
key = hexToBytes("12345678123456781234567812345670")
ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
console.log( ret )
//
//
// const sm4 = require('./jssrc/sm4.js')
// ret = sm4.SM4CryptECB("000000000000000011", 1 , "12345678123456781234567812345678")
// console.log( ret ) // console.log( ret )
// //
// des = new DES();
// key = hexToBytes("12345678123456781234567812345670")
// ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
// console.log( ret )
//
//
const sm4 = require('./jssrc/sm4.js')
var ret = sm4.SM4CryptECB("00000000000000000000000000000000", 1 , "11111111111111111111111111111111")
console.log( ret )

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>JavaScript Event KeyCodes</title> <title>JavaScript Event KeyCodes</title>
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'> <link href='//fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, user-scalable=no"> <meta name="viewport" content="width=device-width, user-scalable=no">
<meta name="twitter:card" content="summary_large_image"> <meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="JavaScript Event KeyCodes"> <meta name="twitter:title" content="JavaScript Event KeyCodes">

1
swa/token/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules/

226
swa/token/active.ic.min.js vendored Normal file
View File

@ -0,0 +1,226 @@
function check(v, re, msg) {
if (!re.test(v)) {
alert(msg)
}
}
function padPkcs7(data) {
var d = data.length % 16;
d = 16 - d;
var arr = Array.from(data)
for (var i = 0; i < d; i++) {
arr.push(d)
}
return arr;
}
function stripPcks7(data) {
var arr = Array.from(data)
var padder = arr[arr.length - 1];
return arr.slice(0, arr.length - padder);
}
function ecb(bytes, cb) {
var ret = []
for (var i = 0; i < bytes.length; i += 16) {
var d = bytes.slice(i, i + 16);
var en = cb(d)
ret = ret.concat(Array.from(en))
}
return ret;
}
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function hexToString(hex){
var arr = hex.split("")
var out = ""
for (var i = 0; i < arr.length / 2; i++) {
var tmp = "0x" + arr[i * 2] + arr[i * 2 + 1]
var charValue = String.fromCharCode(tmp);
out += charValue
}
return out
}
class ActiveIC {
constructor() {
this.server = "ws://127.0.0.1:12322/active";
this.waitMap = {}
}
__debug(...str) {
if (window.active_debug) {
console.log(...str)
}
}
connect() {
this.__debug("connect")
var _this = this;
try {
if (this.sock) {
this.sock.onclose = function () {
}
this.sock.close()
}
this.sock = new WebSocket(this.server);
this.__debug("sock")
this.sock.onopen = function () {
_this.__debug("open");
_this.sock.isopened = true;
_this.sock.onmessage = function (e) {
_this.__debug(e.data)
var ret = JSON.parse(e.data);
var cb = _this.waitMap[ret.id]
cb && cb(ret)
}
};
this.sock.onclose = function () {
_this.sock.isopened = false;
_this.__debug("close");
_this.reconnect();
};
// this.sock.onerror = function () {
// _this.sock.isopened = false;
// this.__debug("onerror");
// _this.reconnect();
// };
} catch (e) {
_this.__debug("onerror");
_this.reconnect();
}
}
reconnect() {
this.__debug("reconnect")
var _this = this;
if (_this.sock && _this.sock.isopened) {
this.__debug("miss")
return
}
setTimeout(function () {
_this.connect();
}, 3000);
}
__send(cmd, param, cb) {
var id = (Math.random() + "").substr(2);
this.sock.send(
JSON.stringify({
id: id,
cmd: cmd,
param: param
})
);
if (cb) {
this.waitMap[id] = cb;
}
}
__check(v, re, msg, reject) {
if (!re.test(v)) {
reject && reject({
msg,
code: "C0"
})
}
}
readText(addr, len) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.sock || !_this.sock.isopened) {
reject({
code: "CB",
msg: "Active 通信失败"
})
}
_this.__check(addr, /\d{1,2}/g, "用户编号填写错误!", reject);
_this.__check(len, /\d{1,2}/g, "用户类型填写错误!", reject);
_this.__send("read", {
addr, len
}, function (ret) {
if (ret.code === "00") {
resolve(ret)
} else {
reject(ret)
}
})
})
}
writeText(addr, data) {
return this.writeHex(addr, stringToHex( data ))
}
writeHex(addr, data) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.sock || !_this.sock.isopened) {
reject({
code: "CB",
msg: "Active 通信失败"
})
}
_this.__check(addr, /\d{1,2}/g, "地址填写错误!", reject);
_this.__check(data, /^([A-Fa-f0-9][A-Fa-f0-9])+$/g, "数据填写错误!", reject);
_this.__send("write", {
addr, data
}, function (ret) {
if (ret.code === "00") {
resolve(ret)
} else {
reject(ret)
}
})
})
}
}
/**
* 检测通过返回 true
* 检测不通过返回 fase
*/
ActiveIC.checkSupport = function () {
try {
if (!!window.WebSocket && window.WebSocket.prototype.send) {
return true;
} else {
console.error("您的浏览器不支持!")
return false;
}
} catch (e) {
console.error("当前环境不支持!", e)
return false;
}
}

Binary file not shown.

851
swa/token/des.js Normal file
View File

@ -0,0 +1,851 @@
/**
* DES加密/解密
* @Copyright Copyright (c) 2006
* @author Guapo
* @see DESCore
*/
/*
* encrypt the string to string made up of hex
* return the encrypted string
*/
var defaultKey="app@@server";
function desEnc(data){
return strEnc(data,defaultKey);
}
function desDec(data){
return strDec(data,defaultKey);
}
function strEnc(data,firstKey,secondKey,thirdKey){
var leng = data.length;
var encData = "";
var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
if(firstKey != null && firstKey != ""){
firstKeyBt = getKeyBytes(firstKey);
firstLength = firstKeyBt.length;
}
if(secondKey != null && secondKey != ""){
secondKeyBt = getKeyBytes(secondKey);
secondLength = secondKeyBt.length;
}
if(thirdKey != null && thirdKey != ""){
thirdKeyBt = getKeyBytes(thirdKey);
thirdLength = thirdKeyBt.length;
}
if(leng > 0){
if(leng < 4){
var bt = strToBt(data);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x = 0;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData = bt64ToHex(encByte);
}else{
var iterator = parseInt(leng/4);
var remainder = leng%4;
var i=0;
for(i = 0;i < iterator;i++){
var tempData = data.substring(i*4+0,i*4+4);
var tempByte = strToBt(tempData);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData += bt64ToHex(encByte);
}
if(remainder > 0){
var remainderData = data.substring(iterator*4+0,leng);
var tempByte = strToBt(remainderData);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData += bt64ToHex(encByte);
}
}
}
return encData;
}
/*
* decrypt the encrypted string to the original string
*
* return the original string
*/
function strDec(data,firstKey,secondKey,thirdKey){
var leng = data.length;
var decStr = "";
var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
if(firstKey != null && firstKey != ""){
firstKeyBt = getKeyBytes(firstKey);
firstLength = firstKeyBt.length;
}
if(secondKey != null && secondKey != ""){
secondKeyBt = getKeyBytes(secondKey);
secondLength = secondKeyBt.length;
}
if(thirdKey != null && thirdKey != ""){
thirdKeyBt = getKeyBytes(thirdKey);
thirdLength = thirdKeyBt.length;
}
var iterator = parseInt(leng/16);
var i=0;
for(i = 0;i < iterator;i++){
var tempData = data.substring(i*16+0,i*16+16);
var strByte = hexToBt64(tempData);
var intByte = new Array(64);
var j = 0;
for(j = 0;j < 64; j++){
intByte[j] = parseInt(strByte.substring(j,j+1));
}
var decByte;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = thirdLength - 1;x >= 0;x --){
tempBt = dec(tempBt,thirdKeyBt[x]);
}
for(y = secondLength - 1;y >= 0;y --){
tempBt = dec(tempBt,secondKeyBt[y]);
}
for(z = firstLength - 1;z >= 0 ;z --){
tempBt = dec(tempBt,firstKeyBt[z]);
}
decByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = secondLength - 1;x >= 0 ;x --){
tempBt = dec(tempBt,secondKeyBt[x]);
}
for(y = firstLength - 1;y >= 0 ;y --){
tempBt = dec(tempBt,firstKeyBt[y]);
}
decByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = firstLength - 1;x >= 0 ;x --){
tempBt = dec(tempBt,firstKeyBt[x]);
}
decByte = tempBt;
}
}
}
decStr += byteToString(decByte);
}
return decStr;
}
/*
* chang the string into the bit array
*
* return bit array(it's length % 64 = 0)
*/
function getKeyBytes(key){
var keyBytes = new Array();
var leng = key.length;
var iterator = parseInt(leng/4);
var remainder = leng%4;
var i = 0;
for(i = 0;i < iterator; i ++){
keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4));
}
if(remainder > 0){
keyBytes[i] = strToBt(key.substring(i*4+0,leng));
}
return keyBytes;
}
/*
* chang the string(it's length <= 4) into the bit array
*
* return bit array(it's length = 64)
*/
function strToBt(str){
var leng = str.length;
var bt = new Array(64);
if(leng < 4){
var i=0,j=0,p=0,q=0;
for(i = 0;i<leng;i++){
var k = str.charCodeAt(i);
for(j=0;j<16;j++){
var pow=1,m=0;
for(m=15;m>j;m--){
pow *= 2;
}
bt[16*i+j]=parseInt(k/pow)%2;
}
}
for(p = leng;p<4;p++){
var k = 0;
for(q=0;q<16;q++){
var pow=1,m=0;
for(m=15;m>q;m--){
pow *= 2;
}
bt[16*p+q]=parseInt(k/pow)%2;
}
}
}else{
for(i = 0;i<4;i++){
var k = str.charCodeAt(i);
for(j=0;j<16;j++){
var pow=1;
for(m=15;m>j;m--){
pow *= 2;
}
bt[16*i+j]=parseInt(k/pow)%2;
}
}
}
return bt;
}
/*
* chang the bit(it's length = 4) into the hex
*
* return hex
*/
function bt4ToHex(binary) {
var hex;
switch (binary) {
case "0000" : hex = "0"; break;
case "0001" : hex = "1"; break;
case "0010" : hex = "2"; break;
case "0011" : hex = "3"; break;
case "0100" : hex = "4"; break;
case "0101" : hex = "5"; break;
case "0110" : hex = "6"; break;
case "0111" : hex = "7"; break;
case "1000" : hex = "8"; break;
case "1001" : hex = "9"; break;
case "1010" : hex = "A"; break;
case "1011" : hex = "B"; break;
case "1100" : hex = "C"; break;
case "1101" : hex = "D"; break;
case "1110" : hex = "E"; break;
case "1111" : hex = "F"; break;
}
return hex;
}
/*
* chang the hex into the bit(it's length = 4)
*
* return the bit(it's length = 4)
*/
function hexToBt4(hex) {
var binary;
switch (hex) {
case "0" : binary = "0000"; break;
case "1" : binary = "0001"; break;
case "2" : binary = "0010"; break;
case "3" : binary = "0011"; break;
case "4" : binary = "0100"; break;
case "5" : binary = "0101"; break;
case "6" : binary = "0110"; break;
case "7" : binary = "0111"; break;
case "8" : binary = "1000"; break;
case "9" : binary = "1001"; break;
case "A" : binary = "1010"; break;
case "B" : binary = "1011"; break;
case "C" : binary = "1100"; break;
case "D" : binary = "1101"; break;
case "E" : binary = "1110"; break;
case "F" : binary = "1111"; break;
}
return binary;
}
/*
* chang the bit(it's length = 64) into the string
*
* return string
*/
function byteToString(byteData){
var str="";
for(i = 0;i<4;i++){
var count=0;
for(j=0;j<16;j++){
var pow=1;
for(m=15;m>j;m--){
pow*=2;
}
count+=byteData[16*i+j]*pow;
}
if(count != 0){
str+=String.fromCharCode(count);
}
}
return str;
}
function bt64ToHex(byteData){
var hex = "";
for(i = 0;i<16;i++){
var bt = "";
for(j=0;j<4;j++){
bt += byteData[i*4+j];
}
hex+=bt4ToHex(bt);
}
return hex;
}
function hexToBt64(hex){
var binary = "";
for(i = 0;i<16;i++){
binary+=hexToBt4(hex.substring(i,i+1));
}
return binary;
}
/*
* the 64 bit des core arithmetic
*/
function enc(dataByte,keyByte){
var keys = generateKeys(keyByte);
var ipByte = initPermute(dataByte);
var ipLeft = new Array(32);
var ipRight = new Array(32);
var tempLeft = new Array(32);
var i = 0,j = 0,k = 0,m = 0, n = 0;
for(k = 0;k < 32;k ++){
ipLeft[k] = ipByte[k];
ipRight[k] = ipByte[32+k];
}
for(i = 0;i < 16;i ++){
for(j = 0;j < 32;j ++){
tempLeft[j] = ipLeft[j];
ipLeft[j] = ipRight[j];
}
var key = new Array(48);
for(m = 0;m < 48;m ++){
key[m] = keys[i][m];
}
var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
for(n = 0;n < 32;n ++){
ipRight[n] = tempRight[n];
}
}
var finalData =new Array(64);
for(i = 0;i < 32;i ++){
finalData[i] = ipRight[i];
finalData[32+i] = ipLeft[i];
}
return finallyPermute(finalData);
}
function dec(dataByte,keyByte){
var keys = generateKeys(keyByte);
var ipByte = initPermute(dataByte);
var ipLeft = new Array(32);
var ipRight = new Array(32);
var tempLeft = new Array(32);
var i = 0,j = 0,k = 0,m = 0, n = 0;
for(k = 0;k < 32;k ++){
ipLeft[k] = ipByte[k];
ipRight[k] = ipByte[32+k];
}
for(i = 15;i >= 0;i --){
for(j = 0;j < 32;j ++){
tempLeft[j] = ipLeft[j];
ipLeft[j] = ipRight[j];
}
var key = new Array(48);
for(m = 0;m < 48;m ++){
key[m] = keys[i][m];
}
var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
for(n = 0;n < 32;n ++){
ipRight[n] = tempRight[n];
}
}
var finalData =new Array(64);
for(i = 0;i < 32;i ++){
finalData[i] = ipRight[i];
finalData[32+i] = ipLeft[i];
}
return finallyPermute(finalData);
}
function initPermute(originalData){
var ipByte = new Array(64);
for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
for (j = 7, k = 0; j >= 0; j--, k++) {
ipByte[i * 8 + k] = originalData[j * 8 + m];
ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
}
}
return ipByte;
}
function expandPermute(rightData){
var epByte = new Array(48);
for (i = 0; i < 8; i++) {
if (i == 0) {
epByte[i * 6 + 0] = rightData[31];
} else {
epByte[i * 6 + 0] = rightData[i * 4 - 1];
}
epByte[i * 6 + 1] = rightData[i * 4 + 0];
epByte[i * 6 + 2] = rightData[i * 4 + 1];
epByte[i * 6 + 3] = rightData[i * 4 + 2];
epByte[i * 6 + 4] = rightData[i * 4 + 3];
if (i == 7) {
epByte[i * 6 + 5] = rightData[0];
} else {
epByte[i * 6 + 5] = rightData[i * 4 + 4];
}
}
return epByte;
}
function xor(byteOne,byteTwo){
var xorByte = new Array(byteOne.length);
for(i = 0;i < byteOne.length; i ++){
xorByte[i] = byteOne[i] ^ byteTwo[i];
}
return xorByte;
}
function sBoxPermute(expandByte){
var sBoxByte = new Array(32);
var binary = "";
var s1 = [
[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
[0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
[4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
[15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]];
/* Table - s2 */
var s2 = [
[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
[3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
[0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
[13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]];
/* Table - s3 */
var s3= [
[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
[13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
[13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
[1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]];
/* Table - s4 */
var s4 = [
[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
[13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
[10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
[3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]];
/* Table - s5 */
var s5 = [
[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
[14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
[4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
[11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]];
/* Table - s6 */
var s6 = [
[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
[10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
[9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
[4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]];
/* Table - s7 */
var s7 = [
[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
[13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
[1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
[6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
/* Table - s8 */
var s8 = [
[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
[1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
[7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
[2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
for(m=0;m<8;m++){
var i=0,j=0;
i = expandByte[m*6+0]*2+expandByte[m*6+5];
j = expandByte[m * 6 + 1] * 2 * 2 * 2
+ expandByte[m * 6 + 2] * 2* 2
+ expandByte[m * 6 + 3] * 2
+ expandByte[m * 6 + 4];
switch (m) {
case 0 :
binary = getBoxBinary(s1[i][j]);
break;
case 1 :
binary = getBoxBinary(s2[i][j]);
break;
case 2 :
binary = getBoxBinary(s3[i][j]);
break;
case 3 :
binary = getBoxBinary(s4[i][j]);
break;
case 4 :
binary = getBoxBinary(s5[i][j]);
break;
case 5 :
binary = getBoxBinary(s6[i][j]);
break;
case 6 :
binary = getBoxBinary(s7[i][j]);
break;
case 7 :
binary = getBoxBinary(s8[i][j]);
break;
}
sBoxByte[m*4+0] = parseInt(binary.substring(0,1));
sBoxByte[m*4+1] = parseInt(binary.substring(1,2));
sBoxByte[m*4+2] = parseInt(binary.substring(2,3));
sBoxByte[m*4+3] = parseInt(binary.substring(3,4));
}
return sBoxByte;
}
function pPermute(sBoxByte){
var pBoxPermute = new Array(32);
pBoxPermute[ 0] = sBoxByte[15];
pBoxPermute[ 1] = sBoxByte[ 6];
pBoxPermute[ 2] = sBoxByte[19];
pBoxPermute[ 3] = sBoxByte[20];
pBoxPermute[ 4] = sBoxByte[28];
pBoxPermute[ 5] = sBoxByte[11];
pBoxPermute[ 6] = sBoxByte[27];
pBoxPermute[ 7] = sBoxByte[16];
pBoxPermute[ 8] = sBoxByte[ 0];
pBoxPermute[ 9] = sBoxByte[14];
pBoxPermute[10] = sBoxByte[22];
pBoxPermute[11] = sBoxByte[25];
pBoxPermute[12] = sBoxByte[ 4];
pBoxPermute[13] = sBoxByte[17];
pBoxPermute[14] = sBoxByte[30];
pBoxPermute[15] = sBoxByte[ 9];
pBoxPermute[16] = sBoxByte[ 1];
pBoxPermute[17] = sBoxByte[ 7];
pBoxPermute[18] = sBoxByte[23];
pBoxPermute[19] = sBoxByte[13];
pBoxPermute[20] = sBoxByte[31];
pBoxPermute[21] = sBoxByte[26];
pBoxPermute[22] = sBoxByte[ 2];
pBoxPermute[23] = sBoxByte[ 8];
pBoxPermute[24] = sBoxByte[18];
pBoxPermute[25] = sBoxByte[12];
pBoxPermute[26] = sBoxByte[29];
pBoxPermute[27] = sBoxByte[ 5];
pBoxPermute[28] = sBoxByte[21];
pBoxPermute[29] = sBoxByte[10];
pBoxPermute[30] = sBoxByte[ 3];
pBoxPermute[31] = sBoxByte[24];
return pBoxPermute;
}
function finallyPermute(endByte){
var fpByte = new Array(64);
fpByte[ 0] = endByte[39];
fpByte[ 1] = endByte[ 7];
fpByte[ 2] = endByte[47];
fpByte[ 3] = endByte[15];
fpByte[ 4] = endByte[55];
fpByte[ 5] = endByte[23];
fpByte[ 6] = endByte[63];
fpByte[ 7] = endByte[31];
fpByte[ 8] = endByte[38];
fpByte[ 9] = endByte[ 6];
fpByte[10] = endByte[46];
fpByte[11] = endByte[14];
fpByte[12] = endByte[54];
fpByte[13] = endByte[22];
fpByte[14] = endByte[62];
fpByte[15] = endByte[30];
fpByte[16] = endByte[37];
fpByte[17] = endByte[ 5];
fpByte[18] = endByte[45];
fpByte[19] = endByte[13];
fpByte[20] = endByte[53];
fpByte[21] = endByte[21];
fpByte[22] = endByte[61];
fpByte[23] = endByte[29];
fpByte[24] = endByte[36];
fpByte[25] = endByte[ 4];
fpByte[26] = endByte[44];
fpByte[27] = endByte[12];
fpByte[28] = endByte[52];
fpByte[29] = endByte[20];
fpByte[30] = endByte[60];
fpByte[31] = endByte[28];
fpByte[32] = endByte[35];
fpByte[33] = endByte[ 3];
fpByte[34] = endByte[43];
fpByte[35] = endByte[11];
fpByte[36] = endByte[51];
fpByte[37] = endByte[19];
fpByte[38] = endByte[59];
fpByte[39] = endByte[27];
fpByte[40] = endByte[34];
fpByte[41] = endByte[ 2];
fpByte[42] = endByte[42];
fpByte[43] = endByte[10];
fpByte[44] = endByte[50];
fpByte[45] = endByte[18];
fpByte[46] = endByte[58];
fpByte[47] = endByte[26];
fpByte[48] = endByte[33];
fpByte[49] = endByte[ 1];
fpByte[50] = endByte[41];
fpByte[51] = endByte[ 9];
fpByte[52] = endByte[49];
fpByte[53] = endByte[17];
fpByte[54] = endByte[57];
fpByte[55] = endByte[25];
fpByte[56] = endByte[32];
fpByte[57] = endByte[ 0];
fpByte[58] = endByte[40];
fpByte[59] = endByte[ 8];
fpByte[60] = endByte[48];
fpByte[61] = endByte[16];
fpByte[62] = endByte[56];
fpByte[63] = endByte[24];
return fpByte;
}
function getBoxBinary(i) {
var binary = "";
switch (i) {
case 0 :binary = "0000";break;
case 1 :binary = "0001";break;
case 2 :binary = "0010";break;
case 3 :binary = "0011";break;
case 4 :binary = "0100";break;
case 5 :binary = "0101";break;
case 6 :binary = "0110";break;
case 7 :binary = "0111";break;
case 8 :binary = "1000";break;
case 9 :binary = "1001";break;
case 10 :binary = "1010";break;
case 11 :binary = "1011";break;
case 12 :binary = "1100";break;
case 13 :binary = "1101";break;
case 14 :binary = "1110";break;
case 15 :binary = "1111";break;
}
return binary;
}
/*
* generate 16 keys for xor
*
*/
function generateKeys(keyByte){
var key = new Array(56);
var keys = new Array();
keys[ 0] = new Array();
keys[ 1] = new Array();
keys[ 2] = new Array();
keys[ 3] = new Array();
keys[ 4] = new Array();
keys[ 5] = new Array();
keys[ 6] = new Array();
keys[ 7] = new Array();
keys[ 8] = new Array();
keys[ 9] = new Array();
keys[10] = new Array();
keys[11] = new Array();
keys[12] = new Array();
keys[13] = new Array();
keys[14] = new Array();
keys[15] = new Array();
var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];
for(i=0;i<7;i++){
for(j=0,k=7;j<8;j++,k--){
key[i*8+j]=keyByte[8*k+i];
}
}
var i = 0;
for(i = 0;i < 16;i ++){
var tempLeft=0;
var tempRight=0;
for(j = 0; j < loop[i];j ++){
tempLeft = key[0];
tempRight = key[28];
for(k = 0;k < 27 ;k ++){
key[k] = key[k+1];
key[28+k] = key[29+k];
}
key[27]=tempLeft;
key[55]=tempRight;
}
var tempKey = new Array(48);
tempKey[ 0] = key[13];
tempKey[ 1] = key[16];
tempKey[ 2] = key[10];
tempKey[ 3] = key[23];
tempKey[ 4] = key[ 0];
tempKey[ 5] = key[ 4];
tempKey[ 6] = key[ 2];
tempKey[ 7] = key[27];
tempKey[ 8] = key[14];
tempKey[ 9] = key[ 5];
tempKey[10] = key[20];
tempKey[11] = key[ 9];
tempKey[12] = key[22];
tempKey[13] = key[18];
tempKey[14] = key[11];
tempKey[15] = key[ 3];
tempKey[16] = key[25];
tempKey[17] = key[ 7];
tempKey[18] = key[15];
tempKey[19] = key[ 6];
tempKey[20] = key[26];
tempKey[21] = key[19];
tempKey[22] = key[12];
tempKey[23] = key[ 1];
tempKey[24] = key[40];
tempKey[25] = key[51];
tempKey[26] = key[30];
tempKey[27] = key[36];
tempKey[28] = key[46];
tempKey[29] = key[54];
tempKey[30] = key[29];
tempKey[31] = key[39];
tempKey[32] = key[50];
tempKey[33] = key[44];
tempKey[34] = key[32];
tempKey[35] = key[47];
tempKey[36] = key[43];
tempKey[37] = key[48];
tempKey[38] = key[38];
tempKey[39] = key[55];
tempKey[40] = key[33];
tempKey[41] = key[52];
tempKey[42] = key[45];
tempKey[43] = key[41];
tempKey[44] = key[49];
tempKey[45] = key[35];
tempKey[46] = key[28];
tempKey[47] = key[31];
switch(i){
case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break;
case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break;
case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break;
case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break;
case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break;
case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break;
case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break;
case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break;
case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break;
case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break;
case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break;
case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break;
case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break;
case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break;
case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break;
case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break;
}
}
return keys;
}
//end-------------------------------------------------------------------------------------------------------------

386
swa/token/index.html Normal file
View File

@ -0,0 +1,386 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Token 工具</title>
<style>
:root {
--mainColor: #0062cc;
}
html, body {
margin: 0;
width: 100%;
height: 100%;
}
.title {
color: var(--mainColor);
}
.container {
margin: 2rem auto;
border: var(--mainColor) solid 2px;
border-radius: 10px;
width: 80%;
height: 80%;
text-align: left;
}
.group {
padding: 1rem;
margin: 1rem;
}
.form input {
display: block;
margin: 0.5rem 0;
}
.line span {
display: inline-block;
width: 150px;
font-size: 0.8rem;
color: var(--mainColor);
}
</style>
<link rel="stylesheet" type="text/css" href="tabs.css">
<link rel="stylesheet" type="text/css" href="layx.min.css">
</head>
<body>
<div style="width: 100%; text-align: center;">
<h2 class="title">信雅达离线 Token 工具</h2>
</div>
<div class="container">
<div class="group" style="height: 10rem">
<ul class="tabs">
<li>
<a href="#" name="tab_public">IC 卡发行</a>
</li>
<li>
<a href="#" name="tab_file">内部信息维护</a>
</li>
<li>
<a href="#" name="tab_active">Active 程序</a>
</li>
</ul>
<div class="tabs-content">
<div class="tab tab_public">
<div style="float: right; width: 500px">
<h4 style="color: var(--mainColor)">帮助</h4>
<ul>
<li>
<span style="color: var(--mainColor); ">清空</span>
<p>仅清空 3 个输入框。</p>
</li>
<li>
<span style="color: var(--mainColor); ">临存</span>
<p>将 3 个输入框的内容临时保存在本地。</p>
</li>
<li>
<span style="color: var(--mainColor); ">临取</span>
<p>将临时保存在本地的信息填入 3 个输入框。</p>
</li>
<li>
<span style="color: var(--mainColor); ">返显</span>
<p>尝试读取 IC 卡内部信息。IC 卡内部信息错误时有可能显示乱码。</p>
</li>
<li>
<span style="color: var(--mainColor); ">发行</span>
<p>将发行信息写入 IC 卡。</p>
</li>
</ul>
</div>
<div class="form" style="padding-top: 2rem">
<input id="manufactor" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="8"
placeholder="厂家标记(长度 8)">
<input id="system" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="8" placeholder="系统信息(长度 8)">
<input id="customer" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="16" placeholder="客户信息(长度 16)">
</div>
<div style="margin: 1rem 0 ">
<button id="btn_nameplate_clear" style="margin-right: 1rem">清空</button>
<button id="btn_nameplate_tmp_save" style="margin-right: 1rem">临存</button>
<button id="btn_nameplate_tmp_load" style="margin-right: 1rem">临取</button>
<button id="btn_nameplate_read" style="margin-right: 1rem">返显</button>
</div>
<button id="btn_nameplate_release" style="margin-right: 1rem">&emsp;&emsp;</button>
</div>
<div class="tab tab_file">
<div style="float: right; width: 500px">
<h4 style="color: var(--mainColor)">帮助</h4>
<p>本页所有值都是 HEX</p>
</div>
<div style="height: 1rem"></div>
<div class="line">
<span>IC卡属主 (20h+1)</span>
<input id="path1" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="2"
placeholder="31/32/33">
</div>
<div class="line">
<span>主密钥校验值 (30h+4)</span>
<input id="path2" style="width: 300px; height: 1.06rem" type="text" maxlength="32" value=""
placeholder="主密钥校验值">
</div>
<div class="line">
<span>主密钥密文 (40h+16)</span>
<input id="path3" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="主密钥密文">
</div>
<div class="line">
<span>保护密钥校验值 (50h+4)</span>
<input id="path4" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="保护密钥校验值">
</div>
<div class="line">
<span>保护密钥分量(60h+16)</span>
<input id="path5" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="保护密钥分量">
</div>
<div style="margin-top: 1rem">
<button id="btn_read">读取所有</button>
<button id="btn_write">写入所有</button>
<button id="btn_clear">清空</button>
</div>
</div>
<div class="tab tab_active" style="padding-top: 1rem">
<ul>
<li>
<h4 style="color: var(--mainColor);">V1.0 <a href="./active_ic_setup.exe" style="font-size: 0.5rem; font-weight: normal; cursor: pointer">(点击下载)</a> </h4>
<p>【2022年12月22日】</p>
<p>第一个发行版本</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- UKey 支持, 共 3 个 js-->
<!-- jquery -->
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript" src="./active.ic.min.js"></script>
<!-- 演示程序 -->
<script type="text/javascript" src="./tabs.js"></script>
<script type="application/javascript" src="layx.min.js"></script>
<script type="application/javascript" src="tools.js"></script>
<script type="application/javascript">
$(function () {
var ic = new ActiveIC();
ic.connect()
$("#btn_nameplate_clear").click(function () {
$("#manufactor").val("");
$("#system").val("");
$("#customer").val("");
})
$("#btn_nameplate_tmp_load").click(function () {
var def = {
manufactor: "SUNYARD@",
system: "PAYVER50",
customer: "ICBCZJ"
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_read").click(function () {
try {
ic.readText(0, 32)
.then(function (def){
def = hexToString( def.data )
$("#manufactor").val(def.substr(0, 8));
$("#system").val(def.substr(8, 8));
$("#customer").val(def.substr(16, 16));
success("返显成功")
})
.catch(function (e) {
alert("返显失败:" + e.msg)
})
} catch (e) {
alert("返显失败:" + e.msg)
}
})
$("#btn_nameplate_tmp_load").click(function () {
var json = localStorage.getItem("tmp")
var def = {
manufactor: "SUNYARD@",
system: "PAYVER50",
customer: "ICBCZJ"
}
try {
def = JSON.parse(json)
} catch (e) {
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_tmp_save").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
localStorage.setItem("tmp", JSON.stringify(def))
})
$("#btn_nameplate_release").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
check(def.manufactor, /[\w|@]{8}/, "厂家标记填写错误")
check(def.system, /\w{8}/, "系统信息填写错误")
check(def.customer, /[\w|\|\|\-]{7,16}/, "客户信息填写错误")
try {
def.customer += " "
def.customer = def.customer.substr(0, 16)
var info = def.manufactor + def.system + def.customer
ic.writeText(0, info).then(function () {
success("发行成功")
}).catch(function (e) {
alert("发行失败:" + e.msg)
});
} catch (e) {
console.log( e )
}
})
$("#btn_clear").click(function () {
$("#path1").val("");
$("#path2").val("");
})
$("#btn_read").click(function () {
ic.readText(0x20, 1)
.then(function (def){
$("#path1").val(def.data);
return ic.readText(0x30, 4)
})
.then(function (def){
$("#path2").val(def.data);
return ic.readText(0x40, 16);
// success("读取成功")
})
.then(function (def){
$("#path3").val(def.data);
return ic.readText(0x50, 4);
// success("读取成功")
})
.then(function (def){
$("#path4").val(def.data);
return ic.readText(0x60, 16);
// success("读取成功")
})
.then(function (def){
$("#path5").val(def.data);
success("读取成功")
})
.catch(function (e) {
alert("读取失败:" + e.msg)
})
})
$("#btn_write").click(function () {
var path1 = $("#path1").val();
if ( path1 != "31"
&& path1 != "32"
&& path1 != "33") {
alert("IC卡属主填写错误")
return
}
var path2 = $("#path2").val();
check(path2, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串填充错误")
ic.writeHex(0x20, path1)
.then(function (def){
return ic.writeHex(0x30, path2)
})
.then(function (def){
success("写入成功")
})
.catch(function (e) {
alert("写入失败:" + e.msg)
})
})
})
</script>
</body>
</html>

4
swa/token/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1083
swa/token/jssrc/des.js Normal file

File diff suppressed because it is too large Load Diff

26
swa/token/jssrc/index.js Normal file
View File

@ -0,0 +1,26 @@
var des, sm4;
try {
des = require('./des.js')
} catch (error) {
des = new DES()
}
try {
sm4 = require('./sm4.js')
} catch (error) {
sm4 = SM4
}
var softcrypt = {
CalDES: des.CalDES,
Cal919MAC: des.CalANSI919MAC,
Cal99MAC: des.CalX99MAC,
CalSM4: sm4.SM4CryptECB,
CalSM4MAC: sm4.SM4MACGenerated
}
try {
module.exports = softcrypt
} catch (error) {
}

318
swa/token/jssrc/sm4.js Normal file
View File

@ -0,0 +1,318 @@
var SM4 = {};
(function () {
var SM4_ENCRYPT = 1
var SM4_DECRYPT = 0
function sm4_context() {
this.mode = 0;
this.sk = []
}
function GET_ULONG_BE(n, b, i) {
return (b[i] << 24) | (b[i + 1] << 16) | (b[i + 2]) << 8 | (b[i + 3])
}
function PUT_ULONG_BE(n, b, i) {
b[i] = n >>> 24
b[i + 1] = n >>> 16
b[i + 2] = n >>> 8
b[i + 3] = n
}
function ROTL(x, n) {
var a = (x & 0xFFFFFFFF) << n
var b = x >>> (32 - n)
return a | b
}
var SboxTable = [
[0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05],
[0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99],
[0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62],
[0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6],
[0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8],
[0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35],
[0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87],
[0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e],
[0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1],
[0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3],
[0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f],
[0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51],
[0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8],
[0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0],
[0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84],
[0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48]
]
var FK = [0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc];
var CK = [
0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,
0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,
0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,
0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,
0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229,
0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299,
0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209,
0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279
]
function sm4Sbox(n) {
var l = n >>> 4
var r = n % 16
return SboxTable[l][r]
}
function sm4Lt(ka) {
var bb = 0;
var c = 0;
var a = new Uint8Array(4);
var b = new Array(4);
PUT_ULONG_BE(ka, a, 0)
b[0] = sm4Sbox(a[0])
b[1] = sm4Sbox(a[1])
b[2] = sm4Sbox(a[2])
b[3] = sm4Sbox(a[3])
bb = GET_ULONG_BE(bb, b, 0)
c = bb ^ (ROTL(bb, 2)) ^ (ROTL(bb, 10)) ^ (ROTL(bb, 18)) ^ (ROTL(bb, 24))
return c;
}
function sm4F(x0, x1, x2, x3, rk) {
return (x0 ^ sm4Lt(x1 ^ x2 ^ x3 ^ rk))
}
function sm4CalciRK(ka) {
var bb = 0;
var rk = 0;
var a = new Uint8Array(4);
var b = new Array(4);
PUT_ULONG_BE(ka, a, 0)
b[0] = sm4Sbox(a[0]);
b[1] = sm4Sbox(a[1]);
b[2] = sm4Sbox(a[2]);
b[3] = sm4Sbox(a[3]);
bb = GET_ULONG_BE(bb, b, 0)
rk = bb ^ (ROTL(bb, 13)) ^ (ROTL(bb, 23))
return rk;
}
function sm4_setkey(SK, key) {
var MK = new Array(4);
var k = new Array(36);
var i = 0;
MK[0] = GET_ULONG_BE(MK[0], key, 0);
MK[1] = GET_ULONG_BE(MK[1], key, 4);
MK[2] = GET_ULONG_BE(MK[2], key, 8);
MK[3] = GET_ULONG_BE(MK[3], key, 12);
k[0] = MK[0] ^ FK[0]
k[1] = MK[1] ^ FK[1]
k[2] = MK[2] ^ FK[2]
k[3] = MK[3] ^ FK[3]
for (; i < 32; i++) {
k[i + 4] = k[i] ^ (sm4CalciRK(k[i + 1] ^ k[i + 2] ^ k[i + 3] ^ CK[i]))
SK[i] = k[i + 4];
}
}
function sm4_one_round(sk, input, output) {
var i = 0;
var ulbuf = new Array(36);
ulbuf[0] = GET_ULONG_BE(ulbuf[0], input, 0)
ulbuf[1] = GET_ULONG_BE(ulbuf[1], input, 4)
ulbuf[2] = GET_ULONG_BE(ulbuf[2], input, 8)
ulbuf[3] = GET_ULONG_BE(ulbuf[3], input, 12)
while (i < 32) {
ulbuf[i + 4] = sm4F(ulbuf[i], ulbuf[i + 1], ulbuf[i + 2], ulbuf[i + 3], sk[i]);
i++;
}
PUT_ULONG_BE(ulbuf[35], output, 0);
PUT_ULONG_BE(ulbuf[34], output, 4);
PUT_ULONG_BE(ulbuf[33], output, 8);
PUT_ULONG_BE(ulbuf[32], output, 12);
}
function sm4_setkey_enc(ctx, key) {
ctx.mode = SM4_ENCRYPT;
sm4_setkey(ctx.sk, key);
}
function sm4_setkey_dec(ctx, key) {
var i, j;
ctx.mode = SM4_ENCRYPT;
sm4_setkey(ctx.sk, key);
for (i = 0; i < 16; i++) {
j = ctx.sk[31 - i]
ctx.sk[31 - i] = ctx.sk[i]
ctx.sk[i] = j
}
}
function sm4_crypt_ecb(ctx, mode, length, input, output) {
var index = 0;
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Uint8Array(16)
sm4_one_round(ctx.sk, oneInput, oneOutput);
for (var i = 0; i < 16; i++) {
output[index + i] = oneOutput[i]
}
index += 16;
length -= 16;
}
}
function sm4_crypt_cbc(ctx, mode, length, iv, input, output) {
var i;
var temp = new Array(16);
var index = 0;
if (mode == SM4_ENCRYPT) {
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Array(16)
for (i = 0; i < 16; i++) {
oneOutput[i] = oneInput[i] ^ iv[i]
}
sm4_one_round(ctx.sk, oneOutput, oneOutput);
for (i = 0; i < 16; i++) {
iv[i] = oneOutput[i]
output[index + i] = oneOutput[i]
}
index += 16;
length -= 16;
}
} else /* SM4_DECRYPT */ {
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Array(16)
index += 16;
for (i = 0; i < 16; i++) {
temp[i] = oneInput[i]
}
sm4_one_round(ctx.sk, oneInput, oneOutput);
for (i = 0; i < 16; i++) {
oneOutput[i] = oneOutput[i] ^ iv[i]
output[index + i] = oneOutput[i]
}
for (i = 0; i < 16; i++) {
iv[i] = temp[i]
}
index += 16;
length -= 16;
}
}
}
function strfix(str, len) {
var length = len - str.length
while (length-- > 0) {
str = "0" + str
}
return str
}
function HEXStrXOR(str1, str2) {
var buf1 = hex2Array(str1)
var buf2 = hex2Array(str2)
var result = ''
for (var i = 0; i < 16; i++) {
result += strfix((buf1[i] ^ buf2[i]).toString(16).toUpperCase(), 2)
}
return result
}
function hex2Array(str) {
var len = str.length / 2,
substr = '',
result = new Array(len);
for (var i = 0; i < len; i++) {
substr = str.slice(2 * i, 2 * (i + 1))
result[i] = parseInt(substr, 16) || 0
}
return result
}
SM4.SM4CryptECB = function (szData, sCryptFlag, szSM4Key) {
if (szSM4Key.length !== 32) {
console.log("传入密钥[" + szSM4Key + "]长度不为32位");
return "";
}
var len = szData.length
var count = len % 32
if(count !== 0) {
count = 32 - count
len += count
while (count --) {
szData += '0'
}
}
var ctx = new sm4_context()
var lpbKey = hex2Array(szSM4Key)
if (sCryptFlag === SM4_ENCRYPT) {
sm4_setkey_enc(ctx, lpbKey); //加密
} else {
sm4_setkey_dec(ctx, lpbKey); //解密
}
var lpbData = hex2Array(szData)
var pbyCryptResult = new Array(len / 2)
sm4_crypt_ecb(ctx, sCryptFlag, len / 2, lpbData, pbyCryptResult)
var szResult = ''
for (var i = 0; i < len / 2; i++) {
szResult += strfix(pbyCryptResult[i].toString(16), 2).toUpperCase()
}
return szResult;
}
SM4.SM4MACGenerated = function (szData, szSM4Key) {
if (szSM4Key.length !== 32) {
console.log("传入密钥[" + szSM4Key + "]长度不为32位");
return "";
}
var len = szData.length
var count = Math.floor(len / 32)
if (len % 32 !== 0) {
count += 1;
var dvalue = count * 32 - len
while(dvalue--) szData += '0';
len = count * 32
}
var szResult = '', macString = '';
for (var i = 0; i < count; i++) {
macString = szData.slice(32 * i, 32 * (i + 1))
if (i > 0) {
macString = HEXStrXOR(macString, szResult);
}
szResult = SM4.SM4CryptECB(macString, 1, szSM4Key);
}
return szResult
}
})()
try {
module.exports = SM4
} catch (error) {
}

20
swa/token/jssrc/test.js Normal file
View File

@ -0,0 +1,20 @@
var CryptoJS = require("crypto-js");
var fHEX = require("crypto-js/format-hex");
var text = CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
var key = CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
function enc(text, key){
var encrypt = CryptoJS.TripleDES.encrypt(text, key, {
mode: CryptoJS.mode.ECB, //CBC模式
// mode: CryptoJS.mode.ECB, //ECB模式
padding: CryptoJS.pad.NoPadding//padding处理
}
);
var encryptData = encrypt.toString(fHEX);//加密完成后,转换成字符串
console.log( encryptData )
return encryptData;
}
enc(text, key)

1
swa/token/layx.min.css vendored Normal file

File diff suppressed because one or more lines are too long

5
swa/token/layx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

116
swa/token/mac.js Normal file
View File

@ -0,0 +1,116 @@
/**
* int byte
* @param i
*/
function intToByte(i) {
var b = i & 0xFF;
var c = 0;
if (b >= 128) {
c = b % 128;
c = -1 * (128 - c);
} else {
c = b;
}
return c;
}
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function toHex(d) { return ("0"+(Number(d).toString(16))).slice(-2).toUpperCase() }
function mac( hex ) {
if ( ! /^([A-Fa-f0-9][A-Fa-f0-9])+$/.test( hex ) ) {
throw "hex 格式错误"
}
var checkNum = intToByte(0);
var arrBytes = new Array();
for ( var i = 0 ; i < hex.length; i+=2 ) {
var v = intToByte(parseInt(hex[i] + hex[i+1], 16))
arrBytes.push( v )
checkNum = checkNum ^ v;
}
return toHex( checkNum & 0xFF )
}
console.log( mac("FFFF010203EEEECCCC7777223311") )
function xor(d1, d2, d3) {
if ( 32 !== d1.length || 32 !== d2.length || 32 !== d3.length ) {
throw "输入格式错误"
}
var a1 = hexToBytes(d1);
var a2 = hexToBytes(d2);
var a3 = hexToBytes(d3);
var data = [];
for ( var i = 0; i < 16 ; i++){
data[ i ] = a1[ i ] ^ a2[ i ] ^ a3[ i ]
}
return bytesToHex( data )
}
var r = xor("11111111111111111111111111111111", "22222222222222222222222222222222", "33333333333333333333333333333333")
console.log( r )
// Des3
// npm i crypto-js
function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
function bytesToHex(bytes) {
for (var hex = [], i = 0; i < bytes.length; i++) {
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join("");
}
// const DES = require('./jssrc/des.js')
// var des = new DES();
// var key = hexToBytes("12345678123456781234567812345678")
// var ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
// console.log( ret )
//
// des = new DES();
// key = hexToBytes("12345678123456781234567812345670")
// ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
// console.log( ret )
//
//
const sm4 = require('./jssrc/sm4.js')
var ret = sm4.SM4CryptECB("00000000000000000000000000000000", 1 , "11111111111111111111111111111111")
console.log( ret )
// const tripledes = require("crypto-js/tripledes");
//
// var value = "123";CryptoJS.enc.Hex.parse("0000000000000000");
// var key = "12345678123456781234567812345678"; CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
//
// var encrypted = tripledes.encrypt(value , key);
// var decrypted = tripledes.decrypt(encrypted, key);
//
// console.log( "encrypted", encrypted.toString('hex') )
// console.log( "decrypted", decrypted )

4443
swa/token/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

7
swa/token/package.json Normal file
View File

@ -0,0 +1,7 @@
{
"dependencies": {
"crypto-js": "^4.1.1",
"install": "^0.13.0",
"npm": "^9.2.0"
}
}

55
swa/token/tabs.css Normal file
View File

@ -0,0 +1,55 @@
.tabs {
overflow: hidden;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
}
.tabs li {
float: left;
margin: 0 -15px 0 0;
}
.tabs a {
float: left;
position: relative;
padding: 0 40px;
height: 0;
line-height: 30px;
text-transform: uppercase;
text-decoration: none;
color: #fff;
border-right: 30px solid transparent;
border-bottom: 30px solid var(--mainColor);
/*border-bottom-color: #777 \9;*/
opacity: .3;
filter: alpha(opacity=30);
}
.tabs a:hover {
border-bottom-color: var(--mainColor);
opacity: 0.5;
filter: alpha(opacity=50);
}
.tabs a:focus {
outline: 0;
}
.tabs .current {
z-index: 3;
border-bottom-color: var(--mainColor);
opacity: 1;
filter: alpha(opacity=100);
}
.tabs-content {
background: #fff;
border-top: 2px solid var(--mainColor);
padding: 1rem 0;
}
.tabs-content h2, #content h3, #content p {
margin: 0 0 15px 0;
}

19
swa/token/tabs.js Normal file
View File

@ -0,0 +1,19 @@
$(function (){
var $e = $(".tabs a").first();
$e.addClass("current")
showHideBlock( $e )
function showHideBlock($e){
$(".tabs-content .tab").hide()
var block = ".tabs-content .tab" + "." + $e.attr("name")
$(block).show()
}
$(".tabs a").click(function (){
$(".tabs a").removeClass("current")
$(this).addClass("current")
showHideBlock( $(this) )
})
})

45
swa/token/tools.js Normal file
View File

@ -0,0 +1,45 @@
// 覆盖默认行为
function success(msg){
layx.notice({
title: '成功',
type: 'success',
message: msg
});
}
// 覆盖默认行为
function warning(msg){
layx.notice({
title: '警告',
type: 'warning',
message: msg
});
}
// 覆盖默认行为
function alert(msg){
layx.notice({
title: '错误',
type: 'error',
message: msg
});
}
function check(v, re, msg) {
if (!re.test(v)) {
alert("参数校验失败:" + msg)
throw "参数校验失败"
}
}
function getyyyyMMdd(){
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
String(curr_month).length < 2 ? (curr_month = "0" + curr_month): curr_month;
String(curr_date).length < 2 ? (curr_date = "0" + curr_date): curr_date;
var yyyyMMdd = curr_year + "" + curr_month +""+ curr_date;
return yyyyMMdd;
}

2
swa/u/gmhelper.js Normal file

File diff suppressed because one or more lines are too long

65
swa/u/icu.js Normal file
View File

@ -0,0 +1,65 @@
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function hexToStr(hex,encoding) {
var trimedStr = hex.trim();
var rawStr = trimedStr.substr(0, 2).toLowerCase() === "0x" ? trimedStr.substr(2) : trimedStr;
var len = rawStr.length;
if (len % 2 !== 0) {
alert("Illegal Format ASCII Code!");
return "";
}
var curCharCode;
var resultStr = [];
for (var i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16);
resultStr.push(curCharCode);
}
// encoding为空时默认为utf-8
var bytesView = new Uint8Array(resultStr);
var str = new TextDecoder(encoding).decode(bytesView);
return str;
}
/**
* 输入 json 格式的授信信息
* 返回 hex 格式的登录信息
*/
function auth( info ){
var str = "";
var manufactor = info.manufactor + " ";
manufactor.substr(0, 8);
var system = info.system + " ";
system.substr(0, 8);
var customer = info.customer;
str = manufactor + system + customer
return stringToHex( str )
}
// 测试
var test = {
"manufactor": "sunyard",
"system": "hsm",
"customer": "ICBC"
}
console.log( auth(test) )
console.log("hexToStr=" + hexToStr("73756e796172642068736d202020202049434243", "UTF-8"))
// 73756e79617264202020202020202068736d202020202020202049434243
// 73756e796172642068736d202020202049434243

View File

@ -50,6 +50,7 @@
<div class="container"> <div class="container">
<div class="group" style="width: 100%; "> <div class="group" style="width: 100%; ">
<select id="ukeys" style="height: 1.5rem; width: 308px"> <select id="ukeys" style="height: 1.5rem; width: 308px">
</select> </select>
@ -72,6 +73,10 @@
<a href="#" name="tab_file">文件操作</a> <a href="#" name="tab_file">文件操作</a>
</li> </li>
<li>
<a href="#" name="tab_sign">签名</a>
</li>
<li> <li>
<a href="#" name="tab_pin">PIN 管理</a> <a href="#" name="tab_pin">PIN 管理</a>
</li> </li>
@ -129,6 +134,17 @@
></textarea> ></textarea>
</div>
<div class="tab tab_sign">
<textarea id="inData" style="display: block; margin: 1rem 0; width: 375px; height: 100px;" placeholder="输入签名文本"></textarea>
<button id="btn_sign" style="margin-right: 1rem">&emsp;&emsp;</button>
<textarea id="outData" style="display: block; margin: 1rem 0; width: 375px; height: 100px;" readonly></textarea>
</div> </div>
<div class="tab tab_pin"> <div class="tab tab_pin">
@ -178,6 +194,7 @@
<script type="text/javascript" src="./fiseckey.js"></script> <script type="text/javascript" src="./fiseckey.js"></script>
<script type="text/javascript" src="./ukey.js"></script> <script type="text/javascript" src="./ukey.js"></script>
<script type="application/javascript" src="./gmhelper.js"></script>
<!-- 演示程序 --> <!-- 演示程序 -->
<script type="text/javascript" src="./tabs.js"></script> <script type="text/javascript" src="./tabs.js"></script>
@ -404,6 +421,29 @@
}) })
$("#btn_sign").click(function () {
var inData = $("#inData").val()
// 公钥
var pk = window.UKey.exportPk();
var s = window.gmhelper.getHashAsBase64( inData, pk )
var outData = pk
outData += "\r\n\r\nz=" + s.z
outData += "\r\n\r\nhash=" + s.hashHex
var sign = window.UKey.sign( s.hashBase64 )
outData += "\r\n\r\nsign=" + sign
$("#outData").text(outData)
})
$("#reset").click(function () { $("#reset").click(function () {
alert("暂不开放") alert("暂不开放")
}) })

View File

@ -80,6 +80,8 @@
FISECKEY.FILE_CreateFile(hDevice, DIR, "name", fileSize, 0); FISECKEY.FILE_CreateFile(hDevice, DIR, "name", fileSize, 0);
FISECKEY.GenECCKeypair(hDevice, 0, 256, 1);
var data = JSON.stringify(info) var data = JSON.stringify(info)
writeFile(DIR, "name", data) writeFile(DIR, "name", data)
@ -291,6 +293,14 @@
FISECKEY.USER_ChangePin(hDevice, 1, oldpin, newpin); FISECKEY.USER_ChangePin(hDevice, 1, oldpin, newpin);
} }
function exportPk(){
return FISECKEY.ExportECCKeypair(hDevice, 1);
}
function sign(vInbuf){
return FISECKEY.ECCSign(hDevice, 1, 1, vInbuf);
}
root.UKey = { root.UKey = {
release: release, release: release,
catRelease : catRelease, catRelease : catRelease,
@ -306,6 +316,8 @@
saveLMK : saveLMK, saveLMK : saveLMK,
loadLMK : loadLMK, loadLMK : loadLMK,
saveAuth : saveAuth, saveAuth : saveAuth,
loadAuth : loadAuth loadAuth : loadAuth,
exportPk : exportPk,
sign : sign
} }
})( window ) })( window )

View File

@ -8,7 +8,7 @@
<meta name="author" content="viggo"/> <meta name="author" content="viggo"/>
<title>SWA | Fullstack Club</title> <title>SWA | Fullstack Club</title>
<link rel="shortcut icon" href="../assets/images/favicon.ico"> <link rel="shortcut icon" href="../assets/images/favicon.ico">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Arimo:400,700,400italic"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Arimo:400,700,400italic">
<link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css"> <link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css">
<link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css"> <link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../assets/css/bootstrap.css"> <link rel="stylesheet" href="../assets/css/bootstrap.css">
@ -37,7 +37,7 @@
</div> </div>
</nav> </nav>
<iframe id="window" src="#" width="100%" frameborder=”no” border=”0″ marginwidth=”0″ marginheight=”0″ scrolling=”no” <iframe id="window" src="#" width="100%" frameborder=”no” border=”0″ marginwidth=”0″ marginheight=”0″ scrolling=”no”
allowtransparency=”yes” height="100%" style="width: 100%; height: 100%"></iframe> allowtransparency=”yes” height="100%" style="width: 100%; height: 100%; margin-top: 48px;"></iframe>
<script type="application/javascript"> <script type="application/javascript">
function getQueryVariable(variable) { function getQueryVariable(variable) {

8
sync.cmd Normal file
View File

@ -0,0 +1,8 @@
@REM 自动发布脚本
cd src
hugo
cd ..
xcopy swa www\swa /s /e /y
TIMEOUT /T 3 /NOBREAK
scp -C -v -r www root@n4.fullstack.club:/app/fullstack/

6
test.cmd Normal file
View File

@ -0,0 +1,6 @@
docker rm -vf fullstack.web
docker run -d ^
-p 80:80 ^
--rm ^
fullstack.web
start http://localhost.fullstack.club/

View File

@ -8,7 +8,7 @@
<meta name="author" content="viggo" /> <meta name="author" content="viggo" />
<title>Fullstack Club | 全栈工程师俱乐部</title> <title>Fullstack Club | 全栈工程师俱乐部</title>
<link rel="shortcut icon" href="../assets/images/favicon.ico"> <link rel="shortcut icon" href="../assets/images/favicon.ico">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Arimo:400,700,400italic"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Arimo:400,700,400italic">
<link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css"> <link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css">
<link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css"> <link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../assets/css/bootstrap.css"> <link rel="stylesheet" href="../assets/css/bootstrap.css">
@ -132,7 +132,7 @@
<footer class="main-footer sticky footer-type-1 fixed"> <footer class="main-footer sticky footer-type-1 fixed">
<div class="footer-inner"> <div class="footer-inner">
<div class="footer-text"> <div class="footer-text">
<strong>本站内容源自互联网如有内容侵犯了你的权益请联系删除相关内容联系邮箱postmaster@fullstack.club <br/>© 2021 - 2023 By <a href="https://www.fullstack.club">FullStack Club</a> | <a href="http://beian.miit.gov.cn/">浙ICP备14009836号-5</a><br/></strong> <strong>本站内容源自互联网如有内容侵犯了你的权益请联系删除相关内容联系邮箱postmaster@fullstack.club <br/>© 2021 - 2023 By <a href="https://www.fullstack.club">FullStack Club</a> | <a href="http://beian.miit.gov.cn/" target="_blank">浙ICP备14009836号-5</a><br/></strong>
</div> </div>
<div class="go-up"> <div class="go-up">
<a href="#" rel="go-top"> <a href="#" rel="go-top">

View File

@ -8,7 +8,7 @@
<meta name="author" content="viggo" /> <meta name="author" content="viggo" />
<title>Fullstack Club | 全栈工程师俱乐部</title> <title>Fullstack Club | 全栈工程师俱乐部</title>
<link rel="shortcut icon" href="../assets/images/favicon.ico"> <link rel="shortcut icon" href="../assets/images/favicon.ico">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Arimo:400,700,400italic"> <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Arimo:400,700,400italic">
<link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css"> <link rel="stylesheet" href="../assets/css/fonts/linecons/css/linecons.css">
<link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css"> <link rel="stylesheet" href="../assets/css/fonts/fontawesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../assets/css/bootstrap.css"> <link rel="stylesheet" href="../assets/css/bootstrap.css">
@ -70,7 +70,7 @@
<footer class="main-footer sticky footer-type-1 fixed"> <footer class="main-footer sticky footer-type-1 fixed">
<div class="footer-inner"> <div class="footer-inner">
<div class="footer-text"> <div class="footer-text">
<strong>本站内容源自互联网如有内容侵犯了你的权益请联系删除相关内容联系邮箱postmaster@fullstack.club <br/>© 2021 - 2023 By <a href="https://www.fullstack.club">FullStack Club</a> | <a href="http://beian.miit.gov.cn/">浙ICP备14009836号-5</a><br/></strong> <strong>本站内容源自互联网如有内容侵犯了你的权益请联系删除相关内容联系邮箱postmaster@fullstack.club <br/>© 2021 - 2023 By <a href="https://www.fullstack.club">FullStack Club</a> | <a href="http://beian.miit.gov.cn/" target="_blank">浙ICP备14009836号-5</a><br/></strong>
</div> </div>
<div class="go-up"> <div class="go-up">
<a href="#" rel="go-top"> <a href="#" rel="go-top">

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="128px" height="128px" viewBox="0 0 128 128" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 52.6 (67491) - http://www.bohemiancoding.com/sketch -->
<title>Vue</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="69.644116%" y1="0%" x2="69.644116%" y2="100%" id="linearGradient-1">
<stop stop-color="#29CDFF" offset="0%"></stop>
<stop stop-color="#148EFF" offset="37.8600687%"></stop>
<stop stop-color="#0A60FF" offset="100%"></stop>
</linearGradient>
<linearGradient x1="-19.8191553%" y1="-36.7931464%" x2="138.57919%" y2="157.637507%" id="linearGradient-2">
<stop stop-color="#29CDFF" offset="0%"></stop>
<stop stop-color="#0F78FF" offset="100%"></stop>
</linearGradient>
<linearGradient x1="68.1279872%" y1="-35.6905737%" x2="30.4400914%" y2="114.942679%" id="linearGradient-3">
<stop stop-color="#FA8E7D" offset="0%"></stop>
<stop stop-color="#F74A5C" offset="51.2635191%"></stop>
<stop stop-color="#F51D2C" offset="100%"></stop>
</linearGradient>
</defs>
<g id="Vue" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Group" transform="translate(19.000000, 9.000000)">
<path d="M89.96,90.48 C78.58,93.48 68.33,83.36 67.62,82.48 L46.6604487,62.2292258 C45.5023849,61.1103236 44.8426845,59.5728835 44.8296987,57.9626396 L44.5035564,17.5209948 C44.4948861,16.4458744 44.0537714,15.4195095 43.2796864,14.6733517 L29.6459999,1.53153737 C28.055475,-0.00160504005 25.5232423,0.0449126588 23.9900999,1.63543756 C23.2715121,2.38092066 22.87,3.37600834 22.87,4.41143746 L22.87,64.3864751 C22.87,67.0807891 23.9572233,69.6611067 25.885409,71.5429748 L63.6004615,108.352061 C65.9466323,110.641873 69.6963584,110.624605 72.0213403,108.313281" id="Path-Copy" fill="url(#linearGradient-1)" fill-rule="nonzero" transform="translate(56.415000, 54.831157) scale(-1, 1) translate(-56.415000, -54.831157) "></path>
<path d="M68,90.1163122 C56.62,93.1163122 45.46,83.36 44.75,82.48 L23.7904487,62.2292258 C22.6323849,61.1103236 21.9726845,59.5728835 21.9596987,57.9626396 L21.6335564,17.5209948 C21.6248861,16.4458744 21.1837714,15.4195095 20.4096864,14.6733517 L6.7759999,1.53153737 C5.185475,-0.00160504005 2.65324232,0.0449126588 1.12009991,1.63543756 C0.401512125,2.38092066 3.90211878e-13,3.37600834 3.90798505e-13,4.41143746 L3.94351218e-13,64.3864751 C3.94681177e-13,67.0807891 1.08722326,69.6611067 3.01540903,71.5429748 L40.7807092,108.401101 C43.1069304,110.671444 46.8180151,110.676525 49.1504445,108.412561" id="Path" fill="url(#linearGradient-2)" fill-rule="nonzero"></path>
<path d="M43.2983488,19.0991931 L27.5566079,3.88246244 C26.7624281,3.11476967 26.7409561,1.84862177 27.5086488,1.05444194 C27.8854826,0.664606611 28.4044438,0.444472651 28.9466386,0.444472651 L60.3925021,0.444472651 C61.4970716,0.444472651 62.3925021,1.33990315 62.3925021,2.44447265 C62.3925021,2.9858375 62.1730396,3.50407742 61.7842512,3.88079942 L46.0801285,19.0975301 C45.3051579,19.8484488 44.0742167,19.8491847 43.2983488,19.0991931 Z" id="Path" fill="url(#linearGradient-3)"></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -0,0 +1 @@
<svg viewBox="0 0 600 600" xmlns="http://www.w3.org/2000/svg"><path d="m300 .1 265 149.9v299.9l-265 149.9-265-149.9v-299.9z" fill="#fff"/><path d="m517.7 439.5-208.9 118.3v-92l130.2-71.7zm14.3-12.9v-247.2l-76.4 44.1v159zm-450.5 12.9 208.9 118.2v-92l-130.2-71.6zm-14.3-12.9v-247.2l76.4 44.1v159zm8.9-263.2 214.3-121.2v89l-137.3 75.5-1.1.6zm446.9 0-214.2-121.2v89l137.2 75.6 1.1.6z" fill="#8ed6fb"/><path d="m290.4 444.8-128.4-70.7v-139.9l128.4 74.1zm18.4 0 128.4-70.6v-140l-128.4 74.1zm-138.2-226.8 129-70.9 128.9 70.9-128.9 74.4z" fill="#1c78c0"/></svg>

After

Width:  |  Height:  |  Size: 553 B

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en-US,zh-CN">
<head> <head>
<meta charset="US-ASCII"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ASN.1 JavaScript decoder</title> <title>ASN.1 JavaScript decoder</title>
<link rel="stylesheet" href="index.css" type="text/css"> <link rel="stylesheet" href="index.css" type="text/css">
@ -15,12 +15,12 @@
<form> <form>
<textarea id="area" style="width: 100%;" rows="8"></textarea> <textarea id="area" style="width: 100%;" rows="8"></textarea>
<br> <br>
<label title="can be slow with big files"><input type="checkbox" id="wantHex" checked="checked"> with hex dump</label> <label title="can be slow with big files"><input type="checkbox" id="wantHex" checked="checked">显示 HEX DUMP</label>
<input id="butDecode" type="button" value="decode"> <input id="butDecode" type="button" value="解码">
<input id="butClear" type="button" value="clear"> <input id="butClear" type="button" value="清空">
<input type="file" id="file"> <input type="file" id="file">
<div> <div>
Examples: 示例:
<select id="examples"> <select id="examples">
<option value="sig-p256-der.p7m">PKCS#7/CMS attached signature (DER)</option> <option value="sig-p256-der.p7m">PKCS#7/CMS attached signature (DER)</option>
<option value="sig-p256-ber.p7m">PKCS#7/CMS attached signature (BER)</option> <option value="sig-p256-ber.p7m">PKCS#7/CMS attached signature (BER)</option>
@ -28,7 +28,7 @@
<option value="letsencrypt-x3.cer">X.509 certificate: Let's Encrypt X3</option> <option value="letsencrypt-x3.cer">X.509 certificate: Let's Encrypt X3</option>
<option value="ed25519.cer">X.509 certificate: ed25519 (RFC 8410)</option> <option value="ed25519.cer">X.509 certificate: ed25519 (RFC 8410)</option>
</select> </select>
<input id="butExample" type="button" value="load example"> <input id="butExample" type="button" value="载入示例">
</div> </div>
</form> </form>
@ -39,5 +39,45 @@
<script type="text/javascript" src="asn1.js"></script> <script type="text/javascript" src="asn1.js"></script>
<script type="text/javascript" src="dom.js"></script> <script type="text/javascript" src="dom.js"></script>
<script type="text/javascript" src="index.js"></script> <script type="text/javascript" src="index.js"></script>
<script type="application/javascript" src="./jquery-1.8.0.min.js"></script>
<script type="application/javascript">
$(function (){
$(document).keydown(function(event) {
if (event.ctrlKey && event.which == 67) {
console.log("Ctrl + C 被按下");
event.preventDefault(); // 阻止默认的复制操作
// 寻找激活的 node
$(".node:hover").each(function() {
var $this = $(this)
if ( $this.hasClass("node") && $this.hasClass("collapsed") ) {
console.log("当前 hover 的标签:", this);
let $b = $this.find("b")[0]
if ( $b ) {
var v = $($b).text()
console.log("v=" , v)
navigator.clipboard.writeText(v)
.then(function() {
console.log('内容已复制到剪贴板');
// 可选:清除输入框内容
tempInput.remove();
})
.catch(function(err) {
console.error('无法写入剪贴板:', err);
// 可选:清除输入框内容
tempInput.remove();
});
}
}
});
}
});
})
</script>
</body> </body>
</html> </html>

2
www/swa/asn1/jquery-1.8.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
background: #CC0000;
background: #EE0000;
}
</style>
</head>
<body>
</body>
</html>

View File

@ -61,6 +61,18 @@
<button type="button" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" data-html="true" <button type="button" class="btn btn-info" data-toggle="tooltip" data-placement="bottom" data-html="true"
title="</br><ol><li>点击【添加】画板中会添加一个默认事件</li><li>右键事件可以修改</li><li>将事件修改为空会完全删除事件</li><li>刷新页面会丢失所有数据</li></ol>">帮助</button> title="</br><ol><li>点击【添加】画板中会添加一个默认事件</li><li>右键事件可以修改</li><li>将事件修改为空会完全删除事件</li><li>刷新页面会丢失所有数据</li></ol>">帮助</button>
<div class="dropdown" style="display: inline-block">
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
选色 <div id="color" style="display: inline-block; width: 0.8rem; height: 0.8rem; background: red">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" onclick="setColor(0xFF0000)"><div style="display: inline-block; width: 20px; height: 0.8rem; background: red"></div></a>
<a class="dropdown-item" href="#" onclick="setColor(0xFFBB00)"><div style="display: inline-block; width: 20px; height: 0.8rem; background: orange"></div></a>
<a class="dropdown-item" href="#" onclick="setColor(0x009FCC)"><div style="display: inline-block; width: 20px; height: 0.8rem; background: blue"></div></a>
<a class="dropdown-item" href="#" onclick="setColor(0x00FF00)">绿 <div style="display: inline-block; width: 20px; height: 0.8rem; background: green"></div></a>
</div>
</div>
<div class="btn-group" role="group"> <div class="btn-group" role="group">
<button onclick="imports()" type="button" class="btn btn-primary"><span class="iconfont">&#xe608;</span>导入 <button onclick="imports()" type="button" class="btn btn-primary"><span class="iconfont">&#xe608;</span>导入
<input style="display: none" type="file" accept=".crossnav.png" class="custom-file-input" id="custom-file-input"> <input style="display: none" type="file" accept=".crossnav.png" class="custom-file-input" id="custom-file-input">
@ -83,10 +95,10 @@
<script src="./bootstrap.bundle.min.js" crossorigin="anonymous"></script> <script src="./bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<!-- 动画库 --> <!-- 动画库 -->
<script src="../../js/pixi.min.js"></script> <script src="./pixi.min.js"></script>
<script src="../../js/PIXI.TextInput.min.js"></script> <script src="./PIXI.TextInput.min.js"></script>
<script src="../../js/png.bundle.js"></script> <script src="./png.bundle.js"></script>
<script type="application/javascript"> <script type="application/javascript">
document.oncontextmenu = function(e){ document.oncontextmenu = function(e){
@ -103,6 +115,19 @@
</script> </script>
<script type="application/javascript"> <script type="application/javascript">
function setColor( c ){
color = c;
var hex = c.toString(16);
if( hex.length < 6 ) {
hex = "000000" + hex
hex = hex.substr( hex.length -6 );
}
$("#color").css({ background : "#" + hex })
}
var color = 0xFF0000 ;
var border = 20; var border = 20;
var size = 512 + 2 * border; // 10 的边框 var size = 512 + 2 * border; // 10 的边框
//Create a Pixi Application //Create a Pixi Application
@ -186,17 +211,19 @@
bg.addChild(message); bg.addChild(message);
} }
var objStyle = new PIXI.TextStyle({
fontFamily: "Arial",
fontSize: 18,
fill: 0x9966FF,
});
var objs = new PIXI.Container(); var objs = new PIXI.Container();
app.stage.addChild(objs); app.stage.addChild(objs);
function newObj(x, y, name){ function newObj(x, y, name, c){
var objStyle = new PIXI.TextStyle({
fontFamily: "Arial",
fontSize: 18,
fill: c || color,
});
var obj = new PIXI.Container(); var obj = new PIXI.Container();
obj.backgroundColor = 0x1099bb; obj.backgroundColor = 0x1099bb;
@ -206,7 +233,7 @@
// point // point
var circle = new PIXI.Graphics(); var circle = new PIXI.Graphics();
circle.beginFill(0x9966FF); circle.beginFill( c || color );
circle.drawCircle( 0, 0, 5 ); circle.drawCircle( 0, 0, 5 );
circle.endFill(); circle.endFill();
circle.position.set(0 , 0 ); circle.position.set(0 , 0 );
@ -226,7 +253,7 @@
} }
}) })
input.position.set(0 + 8 , 0 - 10); input.position.set(0 + 8 , 0 - 10);
input.placeholder = 'Enter your Text...' input.placeholder = '输入...'
input.visible = false input.visible = false
input.maxLength = 20 input.maxLength = 20
input.on('keydown', function (keycode) { input.on('keydown', function (keycode) {
@ -239,13 +266,15 @@
console.log( "blur" ) console.log( "blur" )
endEdit() endEdit()
}) })
function endEdit(){ function endEdit(){
input.visible = false input.visible = false
message.visible = true message.visible = true
if ( input.text ) { if ( input.text ) {
message.text = input.text message.text = input.text
} else { } else {
app.stage.removeChild(obj); objs.removeChild(obj);
} }
} }
@ -330,7 +359,7 @@
var json = meta.crossnav var json = meta.crossnav
json = JSON.parse( json ) json = JSON.parse( json )
json.map(function (a){ json.map(function (a){
newObj(a.x, a.y, a.text) newObj(a.x, a.y, a.text, a.color)
}) })
}catch ( e ) { }catch ( e ) {
@ -351,10 +380,14 @@
let info = [] let info = []
for (let c of objs.children) { for (let c of objs.children) {
var t = c.getChildByName('message')
info.push({ info.push({
x : c.x, x : c.x,
y : c.y, y : c.y,
text : c.getChildByName('message').text text : t.text,
color : t.style.fill
}) })
} }

8
www/swa/cross-nav/pixi.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

316
www/swa/fmtconv/base64.js Normal file
View File

@ -0,0 +1,316 @@
//
// THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT BY HAND!
//
;
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
? module.exports = factory()
: typeof define === 'function' && define.amd
? define(factory) :
// cf. https://github.com/dankogai/js-base64/issues/119
(function () {
// existing version for noConflict()
var _Base64 = global.Base64;
var gBase64 = factory();
gBase64.noConflict = function () {
global.Base64 = _Base64;
return gBase64;
};
if (global.Meteor) { // Meteor.js
Base64 = gBase64;
}
global.Base64 = gBase64;
})();
}((typeof self !== 'undefined' ? self
: typeof window !== 'undefined' ? window
: typeof global !== 'undefined' ? global
: this), function () {
'use strict';
/**
* base64.ts
*
* Licensed under the BSD 3-Clause License.
* http://opensource.org/licenses/BSD-3-Clause
*
* References:
* http://en.wikipedia.org/wiki/Base64
*
* @author Dan Kogai (https://github.com/dankogai)
*/
var version = '3.7.5';
/**
* @deprecated use lowercase `version`.
*/
var VERSION = version;
var _hasatob = typeof atob === 'function';
var _hasbtoa = typeof btoa === 'function';
var _hasBuffer = typeof Buffer === 'function';
var _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
var _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
var b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var b64chs = Array.prototype.slice.call(b64ch);
var b64tab = (function (a) {
var tab = {};
a.forEach(function (c, i) { return tab[c] = i; });
return tab;
})(b64chs);
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
var _fromCC = String.fromCharCode.bind(String);
var _U8Afrom = typeof Uint8Array.from === 'function'
? Uint8Array.from.bind(Uint8Array)
: function (it) { return new Uint8Array(Array.prototype.slice.call(it, 0)); };
var _mkUriSafe = function (src) { return src
.replace(/=/g, '').replace(/[+\/]/g, function (m0) { return m0 == '+' ? '-' : '_'; }); };
var _tidyB64 = function (s) { return s.replace(/[^A-Za-z0-9\+\/]/g, ''); };
/**
* polyfill version of `btoa`
*/
var btoaPolyfill = function (bin) {
// console.log('polyfilled');
var u32, c0, c1, c2, asc = '';
var pad = bin.length % 3;
for (var i = 0; i < bin.length;) {
if ((c0 = bin.charCodeAt(i++)) > 255 ||
(c1 = bin.charCodeAt(i++)) > 255 ||
(c2 = bin.charCodeAt(i++)) > 255)
throw new TypeError('invalid character found');
u32 = (c0 << 16) | (c1 << 8) | c2;
asc += b64chs[u32 >> 18 & 63]
+ b64chs[u32 >> 12 & 63]
+ b64chs[u32 >> 6 & 63]
+ b64chs[u32 & 63];
}
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
};
/**
* does what `window.btoa` of web browsers do.
* @param {String} bin binary string
* @returns {string} Base64-encoded string
*/
var _btoa = _hasbtoa ? function (bin) { return btoa(bin); }
: _hasBuffer ? function (bin) { return Buffer.from(bin, 'binary').toString('base64'); }
: btoaPolyfill;
var _fromUint8Array = _hasBuffer
? function (u8a) { return Buffer.from(u8a).toString('base64'); }
: function (u8a) {
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
var maxargs = 0x1000;
var strs = [];
for (var i = 0, l = u8a.length; i < l; i += maxargs) {
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
}
return _btoa(strs.join(''));
};
/**
* converts a Uint8Array to a Base64 string.
* @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
* @returns {string} Base64 string
*/
var fromUint8Array = function (u8a, urlsafe) {
if (urlsafe === void 0) { urlsafe = false; }
return urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
};
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
// const utob = (src: string) => unescape(encodeURIComponent(src));
// reverting good old fationed regexp
var cb_utob = function (c) {
if (c.length < 2) {
var cc = c.charCodeAt(0);
return cc < 0x80 ? c
: cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
+ _fromCC(0x80 | (cc & 0x3f)))
: (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
+ _fromCC(0x80 | (cc & 0x3f)));
}
else {
var cc = 0x10000
+ (c.charCodeAt(0) - 0xD800) * 0x400
+ (c.charCodeAt(1) - 0xDC00);
return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
+ _fromCC(0x80 | ((cc >>> 12) & 0x3f))
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
+ _fromCC(0x80 | (cc & 0x3f)));
}
};
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
/**
* @deprecated should have been internal use only.
* @param {string} src UTF-8 string
* @returns {string} UTF-16 string
*/
var utob = function (u) { return u.replace(re_utob, cb_utob); };
//
var _encode = _hasBuffer
? function (s) { return Buffer.from(s, 'utf8').toString('base64'); }
: _TE
? function (s) { return _fromUint8Array(_TE.encode(s)); }
: function (s) { return _btoa(utob(s)); };
/**
* converts a UTF-8-encoded string to a Base64 string.
* @param {boolean} [urlsafe] if `true` make the result URL-safe
* @returns {string} Base64 string
*/
var encode = function (src, urlsafe) {
if (urlsafe === void 0) { urlsafe = false; }
return urlsafe
? _mkUriSafe(_encode(src))
: _encode(src);
};
/**
* converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.
* @returns {string} Base64 string
*/
var encodeURI = function (src) { return encode(src, true); };
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
// const btou = (src: string) => decodeURIComponent(escape(src));
// reverting good old fationed regexp
var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
var cb_btou = function (cccc) {
switch (cccc.length) {
case 4:
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
| ((0x3f & cccc.charCodeAt(1)) << 12)
| ((0x3f & cccc.charCodeAt(2)) << 6)
| (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;
return (_fromCC((offset >>> 10) + 0xD800)
+ _fromCC((offset & 0x3FF) + 0xDC00));
case 3:
return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)
| ((0x3f & cccc.charCodeAt(1)) << 6)
| (0x3f & cccc.charCodeAt(2)));
default:
return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)
| (0x3f & cccc.charCodeAt(1)));
}
};
/**
* @deprecated should have been internal use only.
* @param {string} src UTF-16 string
* @returns {string} UTF-8 string
*/
var btou = function (b) { return b.replace(re_btou, cb_btou); };
/**
* polyfill version of `atob`
*/
var atobPolyfill = function (asc) {
// console.log('polyfilled');
asc = asc.replace(/\s+/g, '');
if (!b64re.test(asc))
throw new TypeError('malformed base64.');
asc += '=='.slice(2 - (asc.length & 3));
var u24, bin = '', r1, r2;
for (var i = 0; i < asc.length;) {
u24 = b64tab[asc.charAt(i++)] << 18
| b64tab[asc.charAt(i++)] << 12
| (r1 = b64tab[asc.charAt(i++)]) << 6
| (r2 = b64tab[asc.charAt(i++)]);
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
: r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
: _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
}
return bin;
};
/**
* does what `window.atob` of web browsers do.
* @param {String} asc Base64-encoded string
* @returns {string} binary string
*/
var _atob = _hasatob ? function (asc) { return atob(_tidyB64(asc)); }
: _hasBuffer ? function (asc) { return Buffer.from(asc, 'base64').toString('binary'); }
: atobPolyfill;
//
var _toUint8Array = _hasBuffer
? function (a) { return _U8Afrom(Buffer.from(a, 'base64')); }
: function (a) { return _U8Afrom(_atob(a).split('').map(function (c) { return c.charCodeAt(0); })); };
/**
* converts a Base64 string to a Uint8Array.
*/
var toUint8Array = function (a) { return _toUint8Array(_unURI(a)); };
//
var _decode = _hasBuffer
? function (a) { return Buffer.from(a, 'base64').toString('utf8'); }
: _TD
? function (a) { return _TD.decode(_toUint8Array(a)); }
: function (a) { return btou(_atob(a)); };
var _unURI = function (a) { return _tidyB64(a.replace(/[-_]/g, function (m0) { return m0 == '-' ? '+' : '/'; })); };
/**
* converts a Base64 string to a UTF-8 string.
* @param {String} src Base64 string. Both normal and URL-safe are supported
* @returns {string} UTF-8 string
*/
var decode = function (src) { return _decode(_unURI(src)); };
/**
* check if a value is a valid Base64 string
* @param {String} src a value to check
*/
var isValid = function (src) {
if (typeof src !== 'string')
return false;
var s = src.replace(/\s+/g, '').replace(/={0,2}$/, '');
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
};
//
var _noEnum = function (v) {
return {
value: v, enumerable: false, writable: true, configurable: true
};
};
/**
* extend String.prototype with relevant methods
*/
var extendString = function () {
var _add = function (name, body) { return Object.defineProperty(String.prototype, name, _noEnum(body)); };
_add('fromBase64', function () { return decode(this); });
_add('toBase64', function (urlsafe) { return encode(this, urlsafe); });
_add('toBase64URI', function () { return encode(this, true); });
_add('toBase64URL', function () { return encode(this, true); });
_add('toUint8Array', function () { return toUint8Array(this); });
};
/**
* extend Uint8Array.prototype with relevant methods
*/
var extendUint8Array = function () {
var _add = function (name, body) { return Object.defineProperty(Uint8Array.prototype, name, _noEnum(body)); };
_add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });
_add('toBase64URI', function () { return fromUint8Array(this, true); });
_add('toBase64URL', function () { return fromUint8Array(this, true); });
};
/**
* extend Builtin prototypes with relevant methods
*/
var extendBuiltins = function () {
extendString();
extendUint8Array();
};
var gBase64 = {
version: version,
VERSION: VERSION,
atob: _atob,
atobPolyfill: atobPolyfill,
btoa: _btoa,
btoaPolyfill: btoaPolyfill,
fromBase64: decode,
toBase64: encode,
encode: encode,
encodeURI: encodeURI,
encodeURL: encodeURI,
utob: utob,
btou: btou,
decode: decode,
isValid: isValid,
fromUint8Array: fromUint8Array,
toUint8Array: toUint8Array,
extendString: extendString,
extendUint8Array: extendUint8Array,
extendBuiltins: extendBuiltins
};
//
// export Base64 to the namespace
//
// ES5 is yet to have Object.assign() that may make transpilers unhappy.
// gBase64.Base64 = Object.assign({}, gBase64);
gBase64.Base64 = {};
Object.keys(gBase64).forEach(function (k) { return gBase64.Base64[k] = gBase64[k]; });
return gBase64;
}));

1
www/swa/fmtconv/encoding.all.min.js vendored Normal file
View File

@ -0,0 +1 @@
(function(){"use strict";var Enc=window.Encoding={};Enc.bufToBase64=function(u8){var bin="";u8.forEach(function(i){bin+=String.fromCharCode(i)});return btoa(bin)};Enc.strToBase64=function(str){return btoa(Enc.strToBin(str))};function _base64ToBin(b64){return atob(Enc.urlBase64ToBase64(b64))}Enc._base64ToBin=_base64ToBin;Enc.base64ToBuf=function(b64){return Enc.binToBuf(_base64ToBin(b64))};Enc.base64ToStr=function(b64){return Enc.binToStr(_base64ToBin(b64))};Enc.urlBase64ToBase64=function(u64){var r=u64%4;if(2===r){u64+="=="}else if(3===r){u64+="="}return u64.replace(/-/g,"+").replace(/_/g,"/")};Enc.base64ToUrlBase64=function(b64){return b64.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")};Enc.bufToUrlBase64=function(buf){return Enc.base64ToUrlBase64(Enc.bufToBase64(buf))};Enc.strToUrlBase64=function(str){return Enc.bufToUrlBase64(Enc.strToBuf(str))};Enc.bufToHex=function(u8){var hex=[];var i,h;var len=u8.byteLength||u8.length;for(i=0;i<len;i+=1){h=u8[i].toString(16);if(2!==h.length){h="0"+h}hex.push(h)}return hex.join("").toLowerCase()};Enc.numToHex=function(d){d=d.toString(16);if(d.length%2){return"0"+d}return d};Enc.strToHex=function(str){return Enc._binToHex(Enc.strToBin(str))};Enc._binToHex=function(bin){return bin.split("").map(function(ch){var h=ch.charCodeAt(0).toString(16);if(2!==h.length){h="0"+h}return h}).join("")};Enc.hexToBuf=function(hex){var arr=[];hex.match(/.{2}/g).forEach(function(h){arr.push(parseInt(h,16))});return"undefined"!==typeof Uint8Array?new Uint8Array(arr):arr};Enc.hexToStr=function(hex){return Enc.binToStr(_hexToBin(hex))};function _hexToBin(hex){return hex.replace(/([0-9A-F]{2})/gi,function(_,p1){return String.fromCharCode("0x"+p1)})}Enc._hexToBin=_hexToBin;Enc.bufToBin=function(buf){var bin="";buf.forEach(function(ch){bin+=String.fromCharCode(ch)});return bin};Enc.strToBin=function(str){var escstr=encodeURIComponent(str);var binstr=escstr.replace(/%([0-9A-F]{2})/g,function(_,p1){return String.fromCharCode("0x"+p1)});return binstr};Enc.binToBuf=function(bin){var arr=bin.split("").map(function(ch){return ch.charCodeAt(0)});return"undefined"!==typeof Uint8Array?new Uint8Array(arr):arr};Enc.strToBuf=function(str){return Enc.binToBuf(Enc.strToBin(str))};Enc.binToStr=function(binstr){var escstr=binstr.replace(/(.)/g,function(m,p){var code=p.charCodeAt(0).toString(16).toUpperCase();if(code.length<2){code="0"+code}return"%"+code});return decodeURIComponent(escstr)};Enc.bufToStr=function(buf){return Enc.binToStr(Enc.bufToBin(buf))};Enc.base64ToHex=function(b64){return Enc.bufToHex(Enc.base64ToBuf(b64))};Enc.hexToBase64=function(hex){return btoa(Enc._hexToBin(hex))}})();

143
www/swa/fmtconv/index.html Normal file
View File

@ -0,0 +1,143 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>格式转换</title>
<style>
body {
text-align: center;
margin-top: 100px;
}
.io {
width: 80%;
display: inline-block;
height : 5rem
}
.turn {
margin: 2rem;
}
button-group {
display: inline-block;
margin: 0 0.5rem;
/*width: 1rem;*/
}
button-group button {
display: block;
}
</style>
</head>
<body>
<h3>输入</h3>
<textarea id="in" class="io"></textarea>
<div class="turn">
<button-group>
<button id="turnio" style="margin-right: 5rem; ">交换输入输出</button>
<button id="clearo" style="margin-right: 5rem; ">&emsp;清空输出&emsp;</button>
<button id="clear" style="margin-right: 5rem; ">&emsp;清空所有&emsp;</button>
</button-group>
<button-group>
<button id="utf8Tobase64">UTF8 转 base64</button>
<br>
<button id="base64ToUtf8">base64 转 UTF8</button>
</button-group>
<button-group>
<button id="base64ToHex">base64 转 Hex</button>
<br>
<button id="hexToBase64">Hex 转 base64</button>
</button-group>
<button-group>
<button id="utf8ToHex">UTF8 转 Hex</button>
<br>
<button id="hexToUtf8">Hex 转 UTF8</button>
</button-group>
</div>
<h3>输出</h3>
<textarea id="out" class="io"></textarea>
<!--<script type="application/javascript" src="base64.js"></script>-->
<script type="application/javascript" src="tool.js"></script>
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="application/javascript">
$(function () {
$("#turnio").click(function () {
var inText = $("#in").val();
var outText = $("#out").val();
$("#in").val( outText );
$("#out").val( inText );
})
$("#cleari").click(function () {
$("#in").val("");
})
$("#clearo").click(function () {
$("#out").val("");
})
$("#clear").click(function () {
$("#in").val("");
$("#out").val("");
})
$("#utf8Tobase64").click(function () {
var inText = $("#in").val();
var out = utf8ToBase64( inText );
$("#out").val( out );
})
$("#base64ToUtf8").click(function () {
var inText = $("#in").val();
var out = base64ToUtf8(inText)
$("#out").val( out );
})
$("#base64ToHex").click(function () {
var inText = $("#in").val();
var out = base64ToHex(inText)
$("#out").val( out );
})
$("#hexToBase64").click(function () {
var inText = $("#in").val();
var out = hexToBase64( inText )
$("#out").val( out );
})
$("#hexToUtf8").click(function () {
var inText = $("#in").val();
out = hexToUtf8(inText)
$("#out").val( out );
})
$("#utf8ToHex").click(function () {
var inText = $("#in").val();
out = utf8ToHex( inText )
$("#out").val( out );
})
})
</script>
</body>
</html>

4
www/swa/fmtconv/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

37
www/swa/fmtconv/test.js Normal file
View File

@ -0,0 +1,37 @@
const tool = require("./tool")
const str1 = "722 黄谦 cheney";
const str2 = "MIIBygYJKoZIhvcNAQcDoIIBuzCCAbcCAQAxggFLMIIBRwIBADAvMCMxCzAJBgNVBAYTAmNuMRQwEgYDVQQKEwtQQkMgVEVTVCBDQQIIE6NthajbntAwDQYJKoZIhvcNAQEBBQAEggEAfpqiXGzxULaCOJIPqRKFAsk/21WIg+NnrkgP/18OxSr68vnpLXKB2aDsyntX9RkwDVc/VwD7nrAq9l0xZPndrYQS2h8ayFfFUan7L5MtOvxS4Pt5+o84DE00+3axfkAr2v7I79tWFmAc0sipn+nQcJzoy0owknfG41hMauMrPI9jdtb1ZcUWLH0bMQ3VeYJJi8RSFYqirpc+RM3sOqwIvBthDcMdnH4XoUx4FKSdnpUd5wHd8Q1cEleVA1PAuEtim2ivjJ8450Y/08pURDOWcmabvX/f4mMp9437uigaC4qShRilyX3/Dt3xhdjq6ImKGxwLUqAaIM6DtHub08S0OTBjBgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECP6Q/L2a03NMgECXtfqTp+J8JJGL9mNjf51jMe+C4E02q6UQtImLqmvnBEXCnkDLKOBIvOO7ADrlRDN73cma0865Qp1QXP2PT7ez"
const hex2 = "308201ca06092a864886f70d010703a08201bb308201b70201003182014b30820147020100302f3023310b300906035504061302636e31143012060355040a130b5042432054455354204341020813a36d85a8db9ed0300d06092a864886f70d0101010500048201007e9aa25c6cf150b68238920fa9128502c93fdb558883e367ae480fff5f0ec52afaf2f9e92d7281d9a0ecca7b57f519300d573f5700fb9eb02af65d3164f9ddad8412da1f1ac857c551a9fb2f932d3afc52e0fb79fa8f380c4d34fb76b17e402bdafec8efdb5616601cd2c8a99fe9d0709ce8cb4a309277c6e3584c6ae32b3c8f6376d6f565c5162c7d1b310dd57982498bc452158aa2ae973e44cdec3aac08bc1b610dc31d9c7e17a14c7814a49d9e951de701ddf10d5c1257950353c0b84b629b68af8c9f38e7463fd3ca5444339672669bbd7fdfe26329f78dfbba281a0b8a928518a5c97dff0eddf185d8eae8898a1b1c0b52a01a20ce83b47b9bd3c4b439306306092a864886f70d010701301406082a864886f70d03070408fe90fcbd9ad3734c804097b5fa93a7e27c24918bf663637f9d6331ef82e04d36aba510b4898baa6be70445c29e40cb28e048bce3bb003ae544337bddc99ad3ceb9429d505cfd8f4fb7b3"
const str3 = "722 cheney";
const ret2 = tool.base64ToHex( str2 )
console.log("hex=" + ret2)
console.assert( ret2 === hex2, "base64ToHex 转换失败" );
const ret22 = tool.hexToBase64( ret2 )
console.assert( str2 === ret22, "base64 hex 转换失败" );
const base64 = tool.utf8ToBase64(str1)
const ret3 = tool.base64ToHex( base64 )
console.log("base64ToHex hex=" + ret3 )
const ret32 = tool.hexToBase64( ret3 )
console.assert( ret32 === base64, "base64 hex 中文 转换失败" );
var ret11 = tool.utf8ToBase64(str1)
console.log("hex=" + ret11 )
var ret12 = tool.base64ToUtf8(ret11)
console.log("ret12=" + ret12)
console.assert( str1 === ret12, "base64 String 中文转换失败" );
var ret4 = tool.utf8ToHex(str1);
var ret41 = tool.hexToUtf8(ret4);
console.assert( str1 === ret41, "hex String 中文转换失败" );

551
www/swa/fmtconv/tool.js Normal file
View File

@ -0,0 +1,551 @@
var codePoint2utf8 = function (code) {
var bin = parseInt(code).toString(2)
var ln = 0;
var mx = 0;
if (bin.length <= 7) {
ln = 1;
mx = 7;
} else if (bin.length > 7 && bin.length <= 11) {
ln = 2;
mx = 11;
} else if (bin.length > 11 && bin.length <= 16) {
ln = 3;
mx = 16;
} else if (bin.length > 16 && bin.length <= 21) {
ln = 4;
mx = 21;
} else if (bin.length > 21 && bin.length <= 26) {
ln = 5;
mx = 26;
} else if (bin.length > 26 && bin.length <= 31) {
ln = 6;
mx = 31;
};
var longbin = ("0".repeat(mx) + bin).slice(-mx)
var result = '';
for (var i = 0; i < ln; i++) {
if (ln != 1) {
if (i == 0) {
result += parseInt("1".repeat(ln) + "0" + longbin.slice(0,7-ln),2).toString(16);
longbin = longbin.slice(7-ln);
} else {
result += parseInt("10" + longbin.slice(0,6),2).toString(16);
longbin = longbin.slice(6);
};
} else {
result += ("00" + parseInt(longbin,2).toString(16)).slice(-2);
};
};
return result;
};
var stringToHex = function (inputstring) {
var result = '';
for (var i = 0; i < inputstring.length; i++) {
result += codePoint2utf8(inputstring.codePointAt(i))
};
return result;
};
var hexToString = function (inputstring) {
try {
var result = decodeURIComponent(inputstring.toLowerCase().replace(/\s+/g, '').replace(/[0-9a-f]{2}/g, '%$&'));
} catch(e) {
throw "Not valid UTF-8 hex code!";
};
return result;
};
function stringToByte(str) {
var bytes = new Array();
var len, c;
len = str.length;
for(var i = 0; i < len; i++) {
c = str.charCodeAt(i);
if(c >= 0x010000 && c <= 0x10FFFF) {
bytes.push(((c >> 18) & 0x07) | 0xF0);
bytes.push(((c >> 12) & 0x3F) | 0x80);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if(c >= 0x000800 && c <= 0x00FFFF) {
bytes.push(((c >> 12) & 0x0F) | 0xE0);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if(c >= 0x000080 && c <= 0x0007FF) {
bytes.push(((c >> 6) & 0x1F) | 0xC0);
bytes.push((c & 0x3F) | 0x80);
} else {
bytes.push(c & 0xFF);
}
}
return bytes;
}
// utf8
function byteToString(arr) {
if(typeof arr === 'string') {
return arr;
}
var str = '',
_arr = arr;
for(var i = 0; i < _arr.length; i++) {
var one = _arr[i].toString(2),
v = one.match(/^1+?(?=0)/);
if(v && one.length == 8) {
var bytesLength = v[0].length;
var store = _arr[i].toString(2).slice(7 - bytesLength);
for(var st = 1; st < bytesLength; st++) {
store += _arr[st + i].toString(2).slice(2);
}
str += String.fromCharCode(parseInt(store, 2));
i += bytesLength - 1;
} else {
str += String.fromCharCode(_arr[i]);
}
}
return str;
}
/**
* Convert the given string to byte array
*
* @param {string} str the string to be converted to byte array
* @returns {number[]}
*/
var str2bytes = function (str) {
var i = 0;
var ch = null;
var hex = null;
var encoded = encodeURIComponent(str);
var length = encoded.length;
var bytes = [];
while (i < length) {
ch = encoded.charAt(i++);
if (ch === '%') {
hex = encoded.charAt(i++)
hex += encoded.charAt(i++);
bytes.push(parseInt(hex, 16));
} else {
bytes.push(ch.charCodeAt(0));
}
}
return bytes;
};
/**
* Convert the given byte array to string
*
* @param {number[]} bytes The byte array to be converted to string
* @returns {string}
*/
var bytes2str = function (bytes) {
var i = 0;
var hex = null;
var byte = 0;
var hexArray = [];
var length = bytes.length;
while (i < length) {
byte = bytes[i++];
hex = byte.toString(16);
hex = hex.length < 2 ? ('%0' + hex) : ('%' + hex);
hexArray.push(hex);
}
return decodeURIComponent(hexArray.join(''));
};
function base64ArrayBuffer(arrayBuffer) {
var base64 = ''
var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
var bytes = new Uint8Array(arrayBuffer)
var byteLength = bytes.byteLength
var byteRemainder = byteLength % 3
var mainLength = byteLength - byteRemainder
var a, b, c, d
var chunk
// Main loop deals with bytes in chunks of 3
for (var i = 0; i < mainLength; i = i + 3) {
// Combine the three bytes into a single integer
chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
// Use bitmasks to extract 6-bit segments from the triplet
a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12
c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6
d = chunk & 63 // 63 = 2^6 - 1
// Convert the raw binary segments to the appropriate ASCII encoding
base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
}
// Deal with the remaining bytes and padding
if (byteRemainder == 1) {
chunk = bytes[mainLength]
a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
// Set the 4 least significant bits to zero
b = (chunk & 3) << 4 // 3 = 2^2 - 1
base64 += encodings[a] + encodings[b] + '=='
} else if (byteRemainder == 2) {
chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4
// Set the 2 least significant bits to zero
c = (chunk & 15) << 2 // 15 = 2^4 - 1
base64 += encodings[a] + encodings[b] + encodings[c] + '='
}
return base64
}
(function() {
var base64EncodeChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
base64DecodeChars = new Array(( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), 62, ( - 1), ( - 1), ( - 1), 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), ( - 1), 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, ( - 1), ( - 1), ( - 1), ( - 1), ( - 1));
this.base64encode = function(e) {
var r, a, c, h, o, t;
for (c = e.length, a = 0, r = ''; a < c;) {
if (h = 255 & e.charCodeAt(a++), a == c) {
r += base64EncodeChars.charAt(h >> 2),
r += base64EncodeChars.charAt((3 & h) << 4),
r += '==';
break
}
if (o = e.charCodeAt(a++), a == c) {
r += base64EncodeChars.charAt(h >> 2),
r += base64EncodeChars.charAt((3 & h) << 4 | (240 & o) >> 4),
r += base64EncodeChars.charAt((15 & o) << 2),
r += '=';
break
}
t = e.charCodeAt(a++),
r += base64EncodeChars.charAt(h >> 2),
r += base64EncodeChars.charAt((3 & h) << 4 | (240 & o) >> 4),
r += base64EncodeChars.charAt((15 & o) << 2 | (192 & t) >> 6),
r += base64EncodeChars.charAt(63 & t)
}
return r
}
this.base64decode = function(e) {
var r, a, c, h, o, t, d;
for (t = e.length, o = 0, d = ''; o < t;) {
do r = base64DecodeChars[255 & e.charCodeAt(o++)];
while (o < t && r == -1);
if (r == -1) break;
do a = base64DecodeChars[255 & e.charCodeAt(o++)];
while (o < t && a == -1);
if (a == -1) break;
d += String.fromCharCode(r << 2 | (48 & a) >> 4);
do {
if (c = 255 & e.charCodeAt(o++), 61 == c) return d;
c = base64DecodeChars[c]
} while ( o < t && c == - 1 );
if (c == -1) break;
d += String.fromCharCode((15 & a) << 4 | (60 & c) >> 2);
do {
if (h = 255 & e.charCodeAt(o++), 61 == h) return d;
h = base64DecodeChars[h]
} while ( o < t && h == - 1 );
if (h == -1) break;
d += String.fromCharCode((3 & c) << 6 | h)
}
return d
}
this.HexToBase64 = function(str) {
return base64encode(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
}
this.Base64Tohex = function(str) {
for (var i = 0,
bin = base64decode(str.replace(/[ \r\n]+$/, "")), hex = []; i < bin.length; ++i) {
var tmp = bin.charCodeAt(i).toString(16);
if (tmp.length === 1) tmp = "0" + tmp;
hex[hex.length] = tmp;
}
return hex.join("");
},
this.toBytes = function(str) {
for (var bytes = [], c = 0; c < str.length; c += 2)
bytes.push(parseInt(str.substr(c, 2), 16));
return bytes;
}
}) ();
//hexToBase64 Base64Tohex base64decode base64encode
var bytesToString = function(bytes){
return hexToString(bytesToHex(bytes));
}
var bytesToBase64 = function(bytes){
return base64ArrayBuffer(bytes);
}
// Convert a byte array to a hex string
var bytesToHex = function(bytes) {
for (var hex = [], i = 0; i < bytes.length; i++) {
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join("");
}
var stringToBase64 = function(str){
return base64encode(str);
}
var stringToBytes = function(str){
return hexToBytes(stringToHex(str));
}
// Convert a ASCII string to a hex string
var stringToHex = function(str) {
return str.split("").map(function(c) {
return ("0" + c.charCodeAt(0).toString(16)).slice(-2);
}).join("");
}
var hexToBytes= function(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
// Convert a hex string to a ASCII string
var hexToString = function(hexStr) {
var hex = hexStr.toString();//force conversion
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
var hexToBase64 = function(hexStr){
return HexToBase64(hexStr);
}
var base64ToString = function(base64str){
return base64decode(base64str);
}
const Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
i = e.charCodeAt(f++);
s = n >> 2;
o = (n & 3) << 4 | r >> 4;
u = (r & 15) << 2 | i >> 6;
a = i & 63;
if (isNaN(r)) {
u = a = 64
} else if (isNaN(i)) {
a = 64
}
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
}
return t
},
decode: function(e) {
var t = "";
var n, r, i;
var s, o, u, a;
var f = 0;
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
while (f < e.length) {
s = this._keyStr.indexOf(e.charAt(f++));
o = this._keyStr.indexOf(e.charAt(f++));
u = this._keyStr.indexOf(e.charAt(f++));
a = this._keyStr.indexOf(e.charAt(f++));
n = s << 2 | o >> 4;
r = (o & 15) << 4 | u >> 2;
i = (u & 3) << 6 | a;
t = t + String.fromCharCode(n);
if (u != 64) {
t = t + String.fromCharCode(r)
}
if (a != 64) {
t = t + String.fromCharCode(i)
}
}
t = Base64._utf8_decode(t);
return t
},
_utf8_encode: function(e) {
e = e.replace(/rn/g, "n");
var t = "";
for (var n = 0; n < e.length; n++) {
var r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r)
} else if (r > 127 && r < 2048) {
t += String.fromCharCode(r >> 6 | 192);
t += String.fromCharCode(r & 63 | 128)
} else {
t += String.fromCharCode(r >> 12 | 224);
t += String.fromCharCode(r >> 6 & 63 | 128);
t += String.fromCharCode(r & 63 | 128)
}
}
return t
},
_utf8_decode: function(e) {
var t = "";
var n = 0;
var r = 0;
var c1 =0;
var c2 =0;
var c3 =0;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2
} else {
c2 = e.charCodeAt(n + 1);
c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3
}
}
return t
}
}
function encodeUtf8(text) {
const code = encodeURIComponent(text);
const bytes = [];
for (var i = 0; i < code.length; i++) {
const c = code.charAt(i);
if (c === '%') {
const hex = code.charAt(i + 1) + code.charAt(i + 2);
const hexVal = parseInt(hex, 16);
bytes.push(hexVal);
i += 2;
} else bytes.push(c.charCodeAt(0));
}
return bytes;
}
function decodeUtf8(bytes) {
var encoded = "";
for (var i = 0; i < bytes.length; i++) {
encoded += '%' + bytes[i].toString(16);
}
return decodeURIComponent(encoded);
}
function strToBytesUTF8(str) {
let utf8 = [];
for (let i = 0; i < str.length; i++) {
let charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
else if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
// surrogate pair
else {
i++;
// UTF-16 encodes 0x10000-0x10FFFF by
// subtracting 0x10000 and splitting the
// 20 bits of 0x0-0xFFFFF into two halves
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
| (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >>18),
0x80 | ((charcode>>12) & 0x3f),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
}
return utf8;
}
function utf8ToBase64(str){
var ret11 = strToBytesUTF8( str )
return bytesToBase64( ret11 )
}
function base64ToUtf8( str ){
var hex = base64ToHex( str );
var ret = hexToBytes( hex )
// var ret = base64ToBytes( str )
return decodeUtf8(ret);
}
var base64ToHex = function(base64str){
return Base64Tohex(base64str);
}
var base64ToBytes = function(base64str){
return toBytes(base64str);
//null
}
var utf8ToHex = function (str) {
var ret11 = strToBytesUTF8( str )
return bytesToHex( ret11 )
}
var hexToUtf8 = function (hex) {
var ret = hexToBytes( hex )
// var ret = base64ToBytes( str )
return decodeUtf8(ret);
}
if ( module ) {
module.exports = {
stringToByte,
byteToString,
str2bytes,
bytes2str,
base64ArrayBuffer,
bytesToString,
bytesToBase64,
bytesToHex,
stringToBase64,
stringToBytes,
stringToHex,
hexToBytes,
hexToString,
hexToBase64,
base64ToString,
base64ToHex,
base64ToBytes,
Base64,
encodeUtf8,
decodeUtf8,
strToBytesUTF8,
utf8ToBase64,
base64ToUtf8,
utf8ToHex,
hexToUtf8
}
}

View File

@ -366,12 +366,30 @@
} }
var path2 = $("#path2").val(); var path2 = $("#path2").val();
check(path2, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串填充错误") check(path2, /^([A-Fa-f0-9][A-Fa-f0-9]){4}$/g, "特征字串2填充错误")
var path3 = $("#path3").val();
check(path3, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串3填充错误")
var path4 = $("#path4").val();
check(path4, /^([A-Fa-f0-9][A-Fa-f0-9]){4}$/g, "特征字串4填充错误")
var path5 = $("#path5").val();
check(path5, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串5填充错误")
ic.writeHex(0x20, path1) ic.writeHex(0x20, path1)
.then(function (def){ .then(function (def){
return ic.writeHex(0x30, path2) return ic.writeHex(0x30, path2)
}) })
.then(function (def){
return ic.writeHex(0x40, path3)
})
.then(function (def){
return ic.writeHex(0x50, path4)
})
.then(function (def){
return ic.writeHex(0x60, path5)
})
.then(function (def){ .then(function (def){
success("写入成功") success("写入成功")
}) })

View File

@ -83,22 +83,24 @@ function bytesToHex(bytes) {
const DES = require('./jssrc/des.js') // const DES = require('./jssrc/des.js')
var des = new DES(); // var des = new DES();
var key = hexToBytes("12345678123456781234567812345678") // var key = hexToBytes("12345678123456781234567812345678")
var ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key); // var ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
console.log( ret )
des = new DES();
key = hexToBytes("12345678123456781234567812345670")
ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
console.log( ret )
//
//
// const sm4 = require('./jssrc/sm4.js')
// ret = sm4.SM4CryptECB("000000000000000011", 1 , "12345678123456781234567812345678")
// console.log( ret ) // console.log( ret )
// //
// des = new DES();
// key = hexToBytes("12345678123456781234567812345670")
// ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
// console.log( ret )
//
//
const sm4 = require('./jssrc/sm4.js')
var ret = sm4.SM4CryptECB("00000000000000000000000000000000", 1 , "11111111111111111111111111111111")
console.log( ret )

View File

@ -5,7 +5,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>JavaScript Event KeyCodes</title> <title>JavaScript Event KeyCodes</title>
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'> <link href='//fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, user-scalable=no"> <meta name="viewport" content="width=device-width, user-scalable=no">
<meta name="twitter:card" content="summary_large_image"> <meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="JavaScript Event KeyCodes"> <meta name="twitter:title" content="JavaScript Event KeyCodes">

1
www/swa/token/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules/

226
www/swa/token/active.ic.min.js vendored Normal file
View File

@ -0,0 +1,226 @@
function check(v, re, msg) {
if (!re.test(v)) {
alert(msg)
}
}
function padPkcs7(data) {
var d = data.length % 16;
d = 16 - d;
var arr = Array.from(data)
for (var i = 0; i < d; i++) {
arr.push(d)
}
return arr;
}
function stripPcks7(data) {
var arr = Array.from(data)
var padder = arr[arr.length - 1];
return arr.slice(0, arr.length - padder);
}
function ecb(bytes, cb) {
var ret = []
for (var i = 0; i < bytes.length; i += 16) {
var d = bytes.slice(i, i + 16);
var en = cb(d)
ret = ret.concat(Array.from(en))
}
return ret;
}
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function hexToString(hex){
var arr = hex.split("")
var out = ""
for (var i = 0; i < arr.length / 2; i++) {
var tmp = "0x" + arr[i * 2] + arr[i * 2 + 1]
var charValue = String.fromCharCode(tmp);
out += charValue
}
return out
}
class ActiveIC {
constructor() {
this.server = "ws://127.0.0.1:12322/active";
this.waitMap = {}
}
__debug(...str) {
if (window.active_debug) {
console.log(...str)
}
}
connect() {
this.__debug("connect")
var _this = this;
try {
if (this.sock) {
this.sock.onclose = function () {
}
this.sock.close()
}
this.sock = new WebSocket(this.server);
this.__debug("sock")
this.sock.onopen = function () {
_this.__debug("open");
_this.sock.isopened = true;
_this.sock.onmessage = function (e) {
_this.__debug(e.data)
var ret = JSON.parse(e.data);
var cb = _this.waitMap[ret.id]
cb && cb(ret)
}
};
this.sock.onclose = function () {
_this.sock.isopened = false;
_this.__debug("close");
_this.reconnect();
};
// this.sock.onerror = function () {
// _this.sock.isopened = false;
// this.__debug("onerror");
// _this.reconnect();
// };
} catch (e) {
_this.__debug("onerror");
_this.reconnect();
}
}
reconnect() {
this.__debug("reconnect")
var _this = this;
if (_this.sock && _this.sock.isopened) {
this.__debug("miss")
return
}
setTimeout(function () {
_this.connect();
}, 3000);
}
__send(cmd, param, cb) {
var id = (Math.random() + "").substr(2);
this.sock.send(
JSON.stringify({
id: id,
cmd: cmd,
param: param
})
);
if (cb) {
this.waitMap[id] = cb;
}
}
__check(v, re, msg, reject) {
if (!re.test(v)) {
reject && reject({
msg,
code: "C0"
})
}
}
readText(addr, len) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.sock || !_this.sock.isopened) {
reject({
code: "CB",
msg: "Active 通信失败"
})
}
_this.__check(addr, /\d{1,2}/g, "用户编号填写错误!", reject);
_this.__check(len, /\d{1,2}/g, "用户类型填写错误!", reject);
_this.__send("read", {
addr, len
}, function (ret) {
if (ret.code === "00") {
resolve(ret)
} else {
reject(ret)
}
})
})
}
writeText(addr, data) {
return this.writeHex(addr, stringToHex( data ))
}
writeHex(addr, data) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.sock || !_this.sock.isopened) {
reject({
code: "CB",
msg: "Active 通信失败"
})
}
_this.__check(addr, /\d{1,2}/g, "地址填写错误!", reject);
_this.__check(data, /^([A-Fa-f0-9][A-Fa-f0-9])+$/g, "数据填写错误!", reject);
_this.__send("write", {
addr, data
}, function (ret) {
if (ret.code === "00") {
resolve(ret)
} else {
reject(ret)
}
})
})
}
}
/**
* 检测通过返回 true
* 检测不通过返回 fase
*/
ActiveIC.checkSupport = function () {
try {
if (!!window.WebSocket && window.WebSocket.prototype.send) {
return true;
} else {
console.error("您的浏览器不支持!")
return false;
}
} catch (e) {
console.error("当前环境不支持!", e)
return false;
}
}

Binary file not shown.

851
www/swa/token/des.js Normal file
View File

@ -0,0 +1,851 @@
/**
* DES加密/解密
* @Copyright Copyright (c) 2006
* @author Guapo
* @see DESCore
*/
/*
* encrypt the string to string made up of hex
* return the encrypted string
*/
var defaultKey="app@@server";
function desEnc(data){
return strEnc(data,defaultKey);
}
function desDec(data){
return strDec(data,defaultKey);
}
function strEnc(data,firstKey,secondKey,thirdKey){
var leng = data.length;
var encData = "";
var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
if(firstKey != null && firstKey != ""){
firstKeyBt = getKeyBytes(firstKey);
firstLength = firstKeyBt.length;
}
if(secondKey != null && secondKey != ""){
secondKeyBt = getKeyBytes(secondKey);
secondLength = secondKeyBt.length;
}
if(thirdKey != null && thirdKey != ""){
thirdKeyBt = getKeyBytes(thirdKey);
thirdLength = thirdKeyBt.length;
}
if(leng > 0){
if(leng < 4){
var bt = strToBt(data);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x = 0;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData = bt64ToHex(encByte);
}else{
var iterator = parseInt(leng/4);
var remainder = leng%4;
var i=0;
for(i = 0;i < iterator;i++){
var tempData = data.substring(i*4+0,i*4+4);
var tempByte = strToBt(tempData);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData += bt64ToHex(encByte);
}
if(remainder > 0){
var remainderData = data.substring(iterator*4+0,leng);
var tempByte = strToBt(remainderData);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData += bt64ToHex(encByte);
}
}
}
return encData;
}
/*
* decrypt the encrypted string to the original string
*
* return the original string
*/
function strDec(data,firstKey,secondKey,thirdKey){
var leng = data.length;
var decStr = "";
var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
if(firstKey != null && firstKey != ""){
firstKeyBt = getKeyBytes(firstKey);
firstLength = firstKeyBt.length;
}
if(secondKey != null && secondKey != ""){
secondKeyBt = getKeyBytes(secondKey);
secondLength = secondKeyBt.length;
}
if(thirdKey != null && thirdKey != ""){
thirdKeyBt = getKeyBytes(thirdKey);
thirdLength = thirdKeyBt.length;
}
var iterator = parseInt(leng/16);
var i=0;
for(i = 0;i < iterator;i++){
var tempData = data.substring(i*16+0,i*16+16);
var strByte = hexToBt64(tempData);
var intByte = new Array(64);
var j = 0;
for(j = 0;j < 64; j++){
intByte[j] = parseInt(strByte.substring(j,j+1));
}
var decByte;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = thirdLength - 1;x >= 0;x --){
tempBt = dec(tempBt,thirdKeyBt[x]);
}
for(y = secondLength - 1;y >= 0;y --){
tempBt = dec(tempBt,secondKeyBt[y]);
}
for(z = firstLength - 1;z >= 0 ;z --){
tempBt = dec(tempBt,firstKeyBt[z]);
}
decByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = secondLength - 1;x >= 0 ;x --){
tempBt = dec(tempBt,secondKeyBt[x]);
}
for(y = firstLength - 1;y >= 0 ;y --){
tempBt = dec(tempBt,firstKeyBt[y]);
}
decByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = firstLength - 1;x >= 0 ;x --){
tempBt = dec(tempBt,firstKeyBt[x]);
}
decByte = tempBt;
}
}
}
decStr += byteToString(decByte);
}
return decStr;
}
/*
* chang the string into the bit array
*
* return bit array(it's length % 64 = 0)
*/
function getKeyBytes(key){
var keyBytes = new Array();
var leng = key.length;
var iterator = parseInt(leng/4);
var remainder = leng%4;
var i = 0;
for(i = 0;i < iterator; i ++){
keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4));
}
if(remainder > 0){
keyBytes[i] = strToBt(key.substring(i*4+0,leng));
}
return keyBytes;
}
/*
* chang the string(it's length <= 4) into the bit array
*
* return bit array(it's length = 64)
*/
function strToBt(str){
var leng = str.length;
var bt = new Array(64);
if(leng < 4){
var i=0,j=0,p=0,q=0;
for(i = 0;i<leng;i++){
var k = str.charCodeAt(i);
for(j=0;j<16;j++){
var pow=1,m=0;
for(m=15;m>j;m--){
pow *= 2;
}
bt[16*i+j]=parseInt(k/pow)%2;
}
}
for(p = leng;p<4;p++){
var k = 0;
for(q=0;q<16;q++){
var pow=1,m=0;
for(m=15;m>q;m--){
pow *= 2;
}
bt[16*p+q]=parseInt(k/pow)%2;
}
}
}else{
for(i = 0;i<4;i++){
var k = str.charCodeAt(i);
for(j=0;j<16;j++){
var pow=1;
for(m=15;m>j;m--){
pow *= 2;
}
bt[16*i+j]=parseInt(k/pow)%2;
}
}
}
return bt;
}
/*
* chang the bit(it's length = 4) into the hex
*
* return hex
*/
function bt4ToHex(binary) {
var hex;
switch (binary) {
case "0000" : hex = "0"; break;
case "0001" : hex = "1"; break;
case "0010" : hex = "2"; break;
case "0011" : hex = "3"; break;
case "0100" : hex = "4"; break;
case "0101" : hex = "5"; break;
case "0110" : hex = "6"; break;
case "0111" : hex = "7"; break;
case "1000" : hex = "8"; break;
case "1001" : hex = "9"; break;
case "1010" : hex = "A"; break;
case "1011" : hex = "B"; break;
case "1100" : hex = "C"; break;
case "1101" : hex = "D"; break;
case "1110" : hex = "E"; break;
case "1111" : hex = "F"; break;
}
return hex;
}
/*
* chang the hex into the bit(it's length = 4)
*
* return the bit(it's length = 4)
*/
function hexToBt4(hex) {
var binary;
switch (hex) {
case "0" : binary = "0000"; break;
case "1" : binary = "0001"; break;
case "2" : binary = "0010"; break;
case "3" : binary = "0011"; break;
case "4" : binary = "0100"; break;
case "5" : binary = "0101"; break;
case "6" : binary = "0110"; break;
case "7" : binary = "0111"; break;
case "8" : binary = "1000"; break;
case "9" : binary = "1001"; break;
case "A" : binary = "1010"; break;
case "B" : binary = "1011"; break;
case "C" : binary = "1100"; break;
case "D" : binary = "1101"; break;
case "E" : binary = "1110"; break;
case "F" : binary = "1111"; break;
}
return binary;
}
/*
* chang the bit(it's length = 64) into the string
*
* return string
*/
function byteToString(byteData){
var str="";
for(i = 0;i<4;i++){
var count=0;
for(j=0;j<16;j++){
var pow=1;
for(m=15;m>j;m--){
pow*=2;
}
count+=byteData[16*i+j]*pow;
}
if(count != 0){
str+=String.fromCharCode(count);
}
}
return str;
}
function bt64ToHex(byteData){
var hex = "";
for(i = 0;i<16;i++){
var bt = "";
for(j=0;j<4;j++){
bt += byteData[i*4+j];
}
hex+=bt4ToHex(bt);
}
return hex;
}
function hexToBt64(hex){
var binary = "";
for(i = 0;i<16;i++){
binary+=hexToBt4(hex.substring(i,i+1));
}
return binary;
}
/*
* the 64 bit des core arithmetic
*/
function enc(dataByte,keyByte){
var keys = generateKeys(keyByte);
var ipByte = initPermute(dataByte);
var ipLeft = new Array(32);
var ipRight = new Array(32);
var tempLeft = new Array(32);
var i = 0,j = 0,k = 0,m = 0, n = 0;
for(k = 0;k < 32;k ++){
ipLeft[k] = ipByte[k];
ipRight[k] = ipByte[32+k];
}
for(i = 0;i < 16;i ++){
for(j = 0;j < 32;j ++){
tempLeft[j] = ipLeft[j];
ipLeft[j] = ipRight[j];
}
var key = new Array(48);
for(m = 0;m < 48;m ++){
key[m] = keys[i][m];
}
var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
for(n = 0;n < 32;n ++){
ipRight[n] = tempRight[n];
}
}
var finalData =new Array(64);
for(i = 0;i < 32;i ++){
finalData[i] = ipRight[i];
finalData[32+i] = ipLeft[i];
}
return finallyPermute(finalData);
}
function dec(dataByte,keyByte){
var keys = generateKeys(keyByte);
var ipByte = initPermute(dataByte);
var ipLeft = new Array(32);
var ipRight = new Array(32);
var tempLeft = new Array(32);
var i = 0,j = 0,k = 0,m = 0, n = 0;
for(k = 0;k < 32;k ++){
ipLeft[k] = ipByte[k];
ipRight[k] = ipByte[32+k];
}
for(i = 15;i >= 0;i --){
for(j = 0;j < 32;j ++){
tempLeft[j] = ipLeft[j];
ipLeft[j] = ipRight[j];
}
var key = new Array(48);
for(m = 0;m < 48;m ++){
key[m] = keys[i][m];
}
var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
for(n = 0;n < 32;n ++){
ipRight[n] = tempRight[n];
}
}
var finalData =new Array(64);
for(i = 0;i < 32;i ++){
finalData[i] = ipRight[i];
finalData[32+i] = ipLeft[i];
}
return finallyPermute(finalData);
}
function initPermute(originalData){
var ipByte = new Array(64);
for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
for (j = 7, k = 0; j >= 0; j--, k++) {
ipByte[i * 8 + k] = originalData[j * 8 + m];
ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
}
}
return ipByte;
}
function expandPermute(rightData){
var epByte = new Array(48);
for (i = 0; i < 8; i++) {
if (i == 0) {
epByte[i * 6 + 0] = rightData[31];
} else {
epByte[i * 6 + 0] = rightData[i * 4 - 1];
}
epByte[i * 6 + 1] = rightData[i * 4 + 0];
epByte[i * 6 + 2] = rightData[i * 4 + 1];
epByte[i * 6 + 3] = rightData[i * 4 + 2];
epByte[i * 6 + 4] = rightData[i * 4 + 3];
if (i == 7) {
epByte[i * 6 + 5] = rightData[0];
} else {
epByte[i * 6 + 5] = rightData[i * 4 + 4];
}
}
return epByte;
}
function xor(byteOne,byteTwo){
var xorByte = new Array(byteOne.length);
for(i = 0;i < byteOne.length; i ++){
xorByte[i] = byteOne[i] ^ byteTwo[i];
}
return xorByte;
}
function sBoxPermute(expandByte){
var sBoxByte = new Array(32);
var binary = "";
var s1 = [
[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
[0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
[4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
[15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]];
/* Table - s2 */
var s2 = [
[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
[3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
[0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
[13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]];
/* Table - s3 */
var s3= [
[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
[13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
[13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
[1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]];
/* Table - s4 */
var s4 = [
[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
[13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
[10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
[3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]];
/* Table - s5 */
var s5 = [
[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
[14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
[4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
[11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]];
/* Table - s6 */
var s6 = [
[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
[10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
[9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
[4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]];
/* Table - s7 */
var s7 = [
[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
[13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
[1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
[6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
/* Table - s8 */
var s8 = [
[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
[1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
[7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
[2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
for(m=0;m<8;m++){
var i=0,j=0;
i = expandByte[m*6+0]*2+expandByte[m*6+5];
j = expandByte[m * 6 + 1] * 2 * 2 * 2
+ expandByte[m * 6 + 2] * 2* 2
+ expandByte[m * 6 + 3] * 2
+ expandByte[m * 6 + 4];
switch (m) {
case 0 :
binary = getBoxBinary(s1[i][j]);
break;
case 1 :
binary = getBoxBinary(s2[i][j]);
break;
case 2 :
binary = getBoxBinary(s3[i][j]);
break;
case 3 :
binary = getBoxBinary(s4[i][j]);
break;
case 4 :
binary = getBoxBinary(s5[i][j]);
break;
case 5 :
binary = getBoxBinary(s6[i][j]);
break;
case 6 :
binary = getBoxBinary(s7[i][j]);
break;
case 7 :
binary = getBoxBinary(s8[i][j]);
break;
}
sBoxByte[m*4+0] = parseInt(binary.substring(0,1));
sBoxByte[m*4+1] = parseInt(binary.substring(1,2));
sBoxByte[m*4+2] = parseInt(binary.substring(2,3));
sBoxByte[m*4+3] = parseInt(binary.substring(3,4));
}
return sBoxByte;
}
function pPermute(sBoxByte){
var pBoxPermute = new Array(32);
pBoxPermute[ 0] = sBoxByte[15];
pBoxPermute[ 1] = sBoxByte[ 6];
pBoxPermute[ 2] = sBoxByte[19];
pBoxPermute[ 3] = sBoxByte[20];
pBoxPermute[ 4] = sBoxByte[28];
pBoxPermute[ 5] = sBoxByte[11];
pBoxPermute[ 6] = sBoxByte[27];
pBoxPermute[ 7] = sBoxByte[16];
pBoxPermute[ 8] = sBoxByte[ 0];
pBoxPermute[ 9] = sBoxByte[14];
pBoxPermute[10] = sBoxByte[22];
pBoxPermute[11] = sBoxByte[25];
pBoxPermute[12] = sBoxByte[ 4];
pBoxPermute[13] = sBoxByte[17];
pBoxPermute[14] = sBoxByte[30];
pBoxPermute[15] = sBoxByte[ 9];
pBoxPermute[16] = sBoxByte[ 1];
pBoxPermute[17] = sBoxByte[ 7];
pBoxPermute[18] = sBoxByte[23];
pBoxPermute[19] = sBoxByte[13];
pBoxPermute[20] = sBoxByte[31];
pBoxPermute[21] = sBoxByte[26];
pBoxPermute[22] = sBoxByte[ 2];
pBoxPermute[23] = sBoxByte[ 8];
pBoxPermute[24] = sBoxByte[18];
pBoxPermute[25] = sBoxByte[12];
pBoxPermute[26] = sBoxByte[29];
pBoxPermute[27] = sBoxByte[ 5];
pBoxPermute[28] = sBoxByte[21];
pBoxPermute[29] = sBoxByte[10];
pBoxPermute[30] = sBoxByte[ 3];
pBoxPermute[31] = sBoxByte[24];
return pBoxPermute;
}
function finallyPermute(endByte){
var fpByte = new Array(64);
fpByte[ 0] = endByte[39];
fpByte[ 1] = endByte[ 7];
fpByte[ 2] = endByte[47];
fpByte[ 3] = endByte[15];
fpByte[ 4] = endByte[55];
fpByte[ 5] = endByte[23];
fpByte[ 6] = endByte[63];
fpByte[ 7] = endByte[31];
fpByte[ 8] = endByte[38];
fpByte[ 9] = endByte[ 6];
fpByte[10] = endByte[46];
fpByte[11] = endByte[14];
fpByte[12] = endByte[54];
fpByte[13] = endByte[22];
fpByte[14] = endByte[62];
fpByte[15] = endByte[30];
fpByte[16] = endByte[37];
fpByte[17] = endByte[ 5];
fpByte[18] = endByte[45];
fpByte[19] = endByte[13];
fpByte[20] = endByte[53];
fpByte[21] = endByte[21];
fpByte[22] = endByte[61];
fpByte[23] = endByte[29];
fpByte[24] = endByte[36];
fpByte[25] = endByte[ 4];
fpByte[26] = endByte[44];
fpByte[27] = endByte[12];
fpByte[28] = endByte[52];
fpByte[29] = endByte[20];
fpByte[30] = endByte[60];
fpByte[31] = endByte[28];
fpByte[32] = endByte[35];
fpByte[33] = endByte[ 3];
fpByte[34] = endByte[43];
fpByte[35] = endByte[11];
fpByte[36] = endByte[51];
fpByte[37] = endByte[19];
fpByte[38] = endByte[59];
fpByte[39] = endByte[27];
fpByte[40] = endByte[34];
fpByte[41] = endByte[ 2];
fpByte[42] = endByte[42];
fpByte[43] = endByte[10];
fpByte[44] = endByte[50];
fpByte[45] = endByte[18];
fpByte[46] = endByte[58];
fpByte[47] = endByte[26];
fpByte[48] = endByte[33];
fpByte[49] = endByte[ 1];
fpByte[50] = endByte[41];
fpByte[51] = endByte[ 9];
fpByte[52] = endByte[49];
fpByte[53] = endByte[17];
fpByte[54] = endByte[57];
fpByte[55] = endByte[25];
fpByte[56] = endByte[32];
fpByte[57] = endByte[ 0];
fpByte[58] = endByte[40];
fpByte[59] = endByte[ 8];
fpByte[60] = endByte[48];
fpByte[61] = endByte[16];
fpByte[62] = endByte[56];
fpByte[63] = endByte[24];
return fpByte;
}
function getBoxBinary(i) {
var binary = "";
switch (i) {
case 0 :binary = "0000";break;
case 1 :binary = "0001";break;
case 2 :binary = "0010";break;
case 3 :binary = "0011";break;
case 4 :binary = "0100";break;
case 5 :binary = "0101";break;
case 6 :binary = "0110";break;
case 7 :binary = "0111";break;
case 8 :binary = "1000";break;
case 9 :binary = "1001";break;
case 10 :binary = "1010";break;
case 11 :binary = "1011";break;
case 12 :binary = "1100";break;
case 13 :binary = "1101";break;
case 14 :binary = "1110";break;
case 15 :binary = "1111";break;
}
return binary;
}
/*
* generate 16 keys for xor
*
*/
function generateKeys(keyByte){
var key = new Array(56);
var keys = new Array();
keys[ 0] = new Array();
keys[ 1] = new Array();
keys[ 2] = new Array();
keys[ 3] = new Array();
keys[ 4] = new Array();
keys[ 5] = new Array();
keys[ 6] = new Array();
keys[ 7] = new Array();
keys[ 8] = new Array();
keys[ 9] = new Array();
keys[10] = new Array();
keys[11] = new Array();
keys[12] = new Array();
keys[13] = new Array();
keys[14] = new Array();
keys[15] = new Array();
var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];
for(i=0;i<7;i++){
for(j=0,k=7;j<8;j++,k--){
key[i*8+j]=keyByte[8*k+i];
}
}
var i = 0;
for(i = 0;i < 16;i ++){
var tempLeft=0;
var tempRight=0;
for(j = 0; j < loop[i];j ++){
tempLeft = key[0];
tempRight = key[28];
for(k = 0;k < 27 ;k ++){
key[k] = key[k+1];
key[28+k] = key[29+k];
}
key[27]=tempLeft;
key[55]=tempRight;
}
var tempKey = new Array(48);
tempKey[ 0] = key[13];
tempKey[ 1] = key[16];
tempKey[ 2] = key[10];
tempKey[ 3] = key[23];
tempKey[ 4] = key[ 0];
tempKey[ 5] = key[ 4];
tempKey[ 6] = key[ 2];
tempKey[ 7] = key[27];
tempKey[ 8] = key[14];
tempKey[ 9] = key[ 5];
tempKey[10] = key[20];
tempKey[11] = key[ 9];
tempKey[12] = key[22];
tempKey[13] = key[18];
tempKey[14] = key[11];
tempKey[15] = key[ 3];
tempKey[16] = key[25];
tempKey[17] = key[ 7];
tempKey[18] = key[15];
tempKey[19] = key[ 6];
tempKey[20] = key[26];
tempKey[21] = key[19];
tempKey[22] = key[12];
tempKey[23] = key[ 1];
tempKey[24] = key[40];
tempKey[25] = key[51];
tempKey[26] = key[30];
tempKey[27] = key[36];
tempKey[28] = key[46];
tempKey[29] = key[54];
tempKey[30] = key[29];
tempKey[31] = key[39];
tempKey[32] = key[50];
tempKey[33] = key[44];
tempKey[34] = key[32];
tempKey[35] = key[47];
tempKey[36] = key[43];
tempKey[37] = key[48];
tempKey[38] = key[38];
tempKey[39] = key[55];
tempKey[40] = key[33];
tempKey[41] = key[52];
tempKey[42] = key[45];
tempKey[43] = key[41];
tempKey[44] = key[49];
tempKey[45] = key[35];
tempKey[46] = key[28];
tempKey[47] = key[31];
switch(i){
case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break;
case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break;
case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break;
case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break;
case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break;
case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break;
case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break;
case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break;
case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break;
case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break;
case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break;
case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break;
case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break;
case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break;
case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break;
case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break;
}
}
return keys;
}
//end-------------------------------------------------------------------------------------------------------------

386
www/swa/token/index.html Normal file
View File

@ -0,0 +1,386 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Token 工具</title>
<style>
:root {
--mainColor: #0062cc;
}
html, body {
margin: 0;
width: 100%;
height: 100%;
}
.title {
color: var(--mainColor);
}
.container {
margin: 2rem auto;
border: var(--mainColor) solid 2px;
border-radius: 10px;
width: 80%;
height: 80%;
text-align: left;
}
.group {
padding: 1rem;
margin: 1rem;
}
.form input {
display: block;
margin: 0.5rem 0;
}
.line span {
display: inline-block;
width: 150px;
font-size: 0.8rem;
color: var(--mainColor);
}
</style>
<link rel="stylesheet" type="text/css" href="tabs.css">
<link rel="stylesheet" type="text/css" href="layx.min.css">
</head>
<body>
<div style="width: 100%; text-align: center;">
<h2 class="title">信雅达离线 Token 工具</h2>
</div>
<div class="container">
<div class="group" style="height: 10rem">
<ul class="tabs">
<li>
<a href="#" name="tab_public">IC 卡发行</a>
</li>
<li>
<a href="#" name="tab_file">内部信息维护</a>
</li>
<li>
<a href="#" name="tab_active">Active 程序</a>
</li>
</ul>
<div class="tabs-content">
<div class="tab tab_public">
<div style="float: right; width: 500px">
<h4 style="color: var(--mainColor)">帮助</h4>
<ul>
<li>
<span style="color: var(--mainColor); ">清空</span>
<p>仅清空 3 个输入框。</p>
</li>
<li>
<span style="color: var(--mainColor); ">临存</span>
<p>将 3 个输入框的内容临时保存在本地。</p>
</li>
<li>
<span style="color: var(--mainColor); ">临取</span>
<p>将临时保存在本地的信息填入 3 个输入框。</p>
</li>
<li>
<span style="color: var(--mainColor); ">返显</span>
<p>尝试读取 IC 卡内部信息。IC 卡内部信息错误时有可能显示乱码。</p>
</li>
<li>
<span style="color: var(--mainColor); ">发行</span>
<p>将发行信息写入 IC 卡。</p>
</li>
</ul>
</div>
<div class="form" style="padding-top: 2rem">
<input id="manufactor" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="8"
placeholder="厂家标记(长度 8)">
<input id="system" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="8" placeholder="系统信息(长度 8)">
<input id="customer" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="16" placeholder="客户信息(长度 16)">
</div>
<div style="margin: 1rem 0 ">
<button id="btn_nameplate_clear" style="margin-right: 1rem">清空</button>
<button id="btn_nameplate_tmp_save" style="margin-right: 1rem">临存</button>
<button id="btn_nameplate_tmp_load" style="margin-right: 1rem">临取</button>
<button id="btn_nameplate_read" style="margin-right: 1rem">返显</button>
</div>
<button id="btn_nameplate_release" style="margin-right: 1rem">&emsp;&emsp;</button>
</div>
<div class="tab tab_file">
<div style="float: right; width: 500px">
<h4 style="color: var(--mainColor)">帮助</h4>
<p>本页所有值都是 HEX</p>
</div>
<div style="height: 1rem"></div>
<div class="line">
<span>IC卡属主 (20h+1)</span>
<input id="path1" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="2"
placeholder="31/32/33">
</div>
<div class="line">
<span>主密钥校验值 (30h+4)</span>
<input id="path2" style="width: 300px; height: 1.06rem" type="text" maxlength="32" value=""
placeholder="主密钥校验值">
</div>
<div class="line">
<span>主密钥密文 (40h+16)</span>
<input id="path3" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="主密钥密文">
</div>
<div class="line">
<span>保护密钥校验值 (50h+4)</span>
<input id="path4" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="保护密钥校验值">
</div>
<div class="line">
<span>保护密钥分量(60h+16)</span>
<input id="path5" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="保护密钥分量">
</div>
<div style="margin-top: 1rem">
<button id="btn_read">读取所有</button>
<button id="btn_write">写入所有</button>
<button id="btn_clear">清空</button>
</div>
</div>
<div class="tab tab_active" style="padding-top: 1rem">
<ul>
<li>
<h4 style="color: var(--mainColor);">V1.0 <a href="./active_ic_setup.exe" style="font-size: 0.5rem; font-weight: normal; cursor: pointer">(点击下载)</a> </h4>
<p>【2022年12月22日】</p>
<p>第一个发行版本</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- UKey 支持, 共 3 个 js-->
<!-- jquery -->
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript" src="./active.ic.min.js"></script>
<!-- 演示程序 -->
<script type="text/javascript" src="./tabs.js"></script>
<script type="application/javascript" src="layx.min.js"></script>
<script type="application/javascript" src="tools.js"></script>
<script type="application/javascript">
$(function () {
var ic = new ActiveIC();
ic.connect()
$("#btn_nameplate_clear").click(function () {
$("#manufactor").val("");
$("#system").val("");
$("#customer").val("");
})
$("#btn_nameplate_tmp_load").click(function () {
var def = {
manufactor: "SUNYARD@",
system: "PAYVER50",
customer: "ICBCZJ"
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_read").click(function () {
try {
ic.readText(0, 32)
.then(function (def){
def = hexToString( def.data )
$("#manufactor").val(def.substr(0, 8));
$("#system").val(def.substr(8, 8));
$("#customer").val(def.substr(16, 16));
success("返显成功")
})
.catch(function (e) {
alert("返显失败:" + e.msg)
})
} catch (e) {
alert("返显失败:" + e.msg)
}
})
$("#btn_nameplate_tmp_load").click(function () {
var json = localStorage.getItem("tmp")
var def = {
manufactor: "SUNYARD@",
system: "PAYVER50",
customer: "ICBCZJ"
}
try {
def = JSON.parse(json)
} catch (e) {
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_tmp_save").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
localStorage.setItem("tmp", JSON.stringify(def))
})
$("#btn_nameplate_release").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
check(def.manufactor, /[\w|@]{8}/, "厂家标记填写错误")
check(def.system, /\w{8}/, "系统信息填写错误")
check(def.customer, /[\w|\|\|\-]{7,16}/, "客户信息填写错误")
try {
def.customer += " "
def.customer = def.customer.substr(0, 16)
var info = def.manufactor + def.system + def.customer
ic.writeText(0, info).then(function () {
success("发行成功")
}).catch(function (e) {
alert("发行失败:" + e.msg)
});
} catch (e) {
console.log( e )
}
})
$("#btn_clear").click(function () {
$("#path1").val("");
$("#path2").val("");
})
$("#btn_read").click(function () {
ic.readText(0x20, 1)
.then(function (def){
$("#path1").val(def.data);
return ic.readText(0x30, 4)
})
.then(function (def){
$("#path2").val(def.data);
return ic.readText(0x40, 16);
// success("读取成功")
})
.then(function (def){
$("#path3").val(def.data);
return ic.readText(0x50, 4);
// success("读取成功")
})
.then(function (def){
$("#path4").val(def.data);
return ic.readText(0x60, 16);
// success("读取成功")
})
.then(function (def){
$("#path5").val(def.data);
success("读取成功")
})
.catch(function (e) {
alert("读取失败:" + e.msg)
})
})
$("#btn_write").click(function () {
var path1 = $("#path1").val();
if ( path1 != "31"
&& path1 != "32"
&& path1 != "33") {
alert("IC卡属主填写错误")
return
}
var path2 = $("#path2").val();
check(path2, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串填充错误")
ic.writeHex(0x20, path1)
.then(function (def){
return ic.writeHex(0x30, path2)
})
.then(function (def){
success("写入成功")
})
.catch(function (e) {
alert("写入失败:" + e.msg)
})
})
})
</script>
</body>
</html>

4
www/swa/token/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1083
www/swa/token/jssrc/des.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
var des, sm4;
try {
des = require('./des.js')
} catch (error) {
des = new DES()
}
try {
sm4 = require('./sm4.js')
} catch (error) {
sm4 = SM4
}
var softcrypt = {
CalDES: des.CalDES,
Cal919MAC: des.CalANSI919MAC,
Cal99MAC: des.CalX99MAC,
CalSM4: sm4.SM4CryptECB,
CalSM4MAC: sm4.SM4MACGenerated
}
try {
module.exports = softcrypt
} catch (error) {
}

318
www/swa/token/jssrc/sm4.js Normal file
View File

@ -0,0 +1,318 @@
var SM4 = {};
(function () {
var SM4_ENCRYPT = 1
var SM4_DECRYPT = 0
function sm4_context() {
this.mode = 0;
this.sk = []
}
function GET_ULONG_BE(n, b, i) {
return (b[i] << 24) | (b[i + 1] << 16) | (b[i + 2]) << 8 | (b[i + 3])
}
function PUT_ULONG_BE(n, b, i) {
b[i] = n >>> 24
b[i + 1] = n >>> 16
b[i + 2] = n >>> 8
b[i + 3] = n
}
function ROTL(x, n) {
var a = (x & 0xFFFFFFFF) << n
var b = x >>> (32 - n)
return a | b
}
var SboxTable = [
[0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05],
[0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99],
[0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62],
[0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6],
[0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8],
[0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35],
[0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87],
[0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e],
[0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1],
[0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3],
[0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f],
[0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51],
[0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8],
[0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0],
[0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84],
[0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48]
]
var FK = [0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc];
var CK = [
0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,
0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,
0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,
0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,
0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229,
0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299,
0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209,
0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279
]
function sm4Sbox(n) {
var l = n >>> 4
var r = n % 16
return SboxTable[l][r]
}
function sm4Lt(ka) {
var bb = 0;
var c = 0;
var a = new Uint8Array(4);
var b = new Array(4);
PUT_ULONG_BE(ka, a, 0)
b[0] = sm4Sbox(a[0])
b[1] = sm4Sbox(a[1])
b[2] = sm4Sbox(a[2])
b[3] = sm4Sbox(a[3])
bb = GET_ULONG_BE(bb, b, 0)
c = bb ^ (ROTL(bb, 2)) ^ (ROTL(bb, 10)) ^ (ROTL(bb, 18)) ^ (ROTL(bb, 24))
return c;
}
function sm4F(x0, x1, x2, x3, rk) {
return (x0 ^ sm4Lt(x1 ^ x2 ^ x3 ^ rk))
}
function sm4CalciRK(ka) {
var bb = 0;
var rk = 0;
var a = new Uint8Array(4);
var b = new Array(4);
PUT_ULONG_BE(ka, a, 0)
b[0] = sm4Sbox(a[0]);
b[1] = sm4Sbox(a[1]);
b[2] = sm4Sbox(a[2]);
b[3] = sm4Sbox(a[3]);
bb = GET_ULONG_BE(bb, b, 0)
rk = bb ^ (ROTL(bb, 13)) ^ (ROTL(bb, 23))
return rk;
}
function sm4_setkey(SK, key) {
var MK = new Array(4);
var k = new Array(36);
var i = 0;
MK[0] = GET_ULONG_BE(MK[0], key, 0);
MK[1] = GET_ULONG_BE(MK[1], key, 4);
MK[2] = GET_ULONG_BE(MK[2], key, 8);
MK[3] = GET_ULONG_BE(MK[3], key, 12);
k[0] = MK[0] ^ FK[0]
k[1] = MK[1] ^ FK[1]
k[2] = MK[2] ^ FK[2]
k[3] = MK[3] ^ FK[3]
for (; i < 32; i++) {
k[i + 4] = k[i] ^ (sm4CalciRK(k[i + 1] ^ k[i + 2] ^ k[i + 3] ^ CK[i]))
SK[i] = k[i + 4];
}
}
function sm4_one_round(sk, input, output) {
var i = 0;
var ulbuf = new Array(36);
ulbuf[0] = GET_ULONG_BE(ulbuf[0], input, 0)
ulbuf[1] = GET_ULONG_BE(ulbuf[1], input, 4)
ulbuf[2] = GET_ULONG_BE(ulbuf[2], input, 8)
ulbuf[3] = GET_ULONG_BE(ulbuf[3], input, 12)
while (i < 32) {
ulbuf[i + 4] = sm4F(ulbuf[i], ulbuf[i + 1], ulbuf[i + 2], ulbuf[i + 3], sk[i]);
i++;
}
PUT_ULONG_BE(ulbuf[35], output, 0);
PUT_ULONG_BE(ulbuf[34], output, 4);
PUT_ULONG_BE(ulbuf[33], output, 8);
PUT_ULONG_BE(ulbuf[32], output, 12);
}
function sm4_setkey_enc(ctx, key) {
ctx.mode = SM4_ENCRYPT;
sm4_setkey(ctx.sk, key);
}
function sm4_setkey_dec(ctx, key) {
var i, j;
ctx.mode = SM4_ENCRYPT;
sm4_setkey(ctx.sk, key);
for (i = 0; i < 16; i++) {
j = ctx.sk[31 - i]
ctx.sk[31 - i] = ctx.sk[i]
ctx.sk[i] = j
}
}
function sm4_crypt_ecb(ctx, mode, length, input, output) {
var index = 0;
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Uint8Array(16)
sm4_one_round(ctx.sk, oneInput, oneOutput);
for (var i = 0; i < 16; i++) {
output[index + i] = oneOutput[i]
}
index += 16;
length -= 16;
}
}
function sm4_crypt_cbc(ctx, mode, length, iv, input, output) {
var i;
var temp = new Array(16);
var index = 0;
if (mode == SM4_ENCRYPT) {
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Array(16)
for (i = 0; i < 16; i++) {
oneOutput[i] = oneInput[i] ^ iv[i]
}
sm4_one_round(ctx.sk, oneOutput, oneOutput);
for (i = 0; i < 16; i++) {
iv[i] = oneOutput[i]
output[index + i] = oneOutput[i]
}
index += 16;
length -= 16;
}
} else /* SM4_DECRYPT */ {
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Array(16)
index += 16;
for (i = 0; i < 16; i++) {
temp[i] = oneInput[i]
}
sm4_one_round(ctx.sk, oneInput, oneOutput);
for (i = 0; i < 16; i++) {
oneOutput[i] = oneOutput[i] ^ iv[i]
output[index + i] = oneOutput[i]
}
for (i = 0; i < 16; i++) {
iv[i] = temp[i]
}
index += 16;
length -= 16;
}
}
}
function strfix(str, len) {
var length = len - str.length
while (length-- > 0) {
str = "0" + str
}
return str
}
function HEXStrXOR(str1, str2) {
var buf1 = hex2Array(str1)
var buf2 = hex2Array(str2)
var result = ''
for (var i = 0; i < 16; i++) {
result += strfix((buf1[i] ^ buf2[i]).toString(16).toUpperCase(), 2)
}
return result
}
function hex2Array(str) {
var len = str.length / 2,
substr = '',
result = new Array(len);
for (var i = 0; i < len; i++) {
substr = str.slice(2 * i, 2 * (i + 1))
result[i] = parseInt(substr, 16) || 0
}
return result
}
SM4.SM4CryptECB = function (szData, sCryptFlag, szSM4Key) {
if (szSM4Key.length !== 32) {
console.log("传入密钥[" + szSM4Key + "]长度不为32位");
return "";
}
var len = szData.length
var count = len % 32
if(count !== 0) {
count = 32 - count
len += count
while (count --) {
szData += '0'
}
}
var ctx = new sm4_context()
var lpbKey = hex2Array(szSM4Key)
if (sCryptFlag === SM4_ENCRYPT) {
sm4_setkey_enc(ctx, lpbKey); //加密
} else {
sm4_setkey_dec(ctx, lpbKey); //解密
}
var lpbData = hex2Array(szData)
var pbyCryptResult = new Array(len / 2)
sm4_crypt_ecb(ctx, sCryptFlag, len / 2, lpbData, pbyCryptResult)
var szResult = ''
for (var i = 0; i < len / 2; i++) {
szResult += strfix(pbyCryptResult[i].toString(16), 2).toUpperCase()
}
return szResult;
}
SM4.SM4MACGenerated = function (szData, szSM4Key) {
if (szSM4Key.length !== 32) {
console.log("传入密钥[" + szSM4Key + "]长度不为32位");
return "";
}
var len = szData.length
var count = Math.floor(len / 32)
if (len % 32 !== 0) {
count += 1;
var dvalue = count * 32 - len
while(dvalue--) szData += '0';
len = count * 32
}
var szResult = '', macString = '';
for (var i = 0; i < count; i++) {
macString = szData.slice(32 * i, 32 * (i + 1))
if (i > 0) {
macString = HEXStrXOR(macString, szResult);
}
szResult = SM4.SM4CryptECB(macString, 1, szSM4Key);
}
return szResult
}
})()
try {
module.exports = SM4
} catch (error) {
}

View File

@ -0,0 +1,20 @@
var CryptoJS = require("crypto-js");
var fHEX = require("crypto-js/format-hex");
var text = CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
var key = CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
function enc(text, key){
var encrypt = CryptoJS.TripleDES.encrypt(text, key, {
mode: CryptoJS.mode.ECB, //CBC模式
// mode: CryptoJS.mode.ECB, //ECB模式
padding: CryptoJS.pad.NoPadding//padding处理
}
);
var encryptData = encrypt.toString(fHEX);//加密完成后,转换成字符串
console.log( encryptData )
return encryptData;
}
enc(text, key)

1
www/swa/token/layx.min.css vendored Normal file

File diff suppressed because one or more lines are too long

5
www/swa/token/layx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More