From a309b65e80f3f21b5ab7c182acb9764f47c677f1 Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: 星期五, 07 六月 2024 15:48:11 +0800
Subject: [PATCH] 登录key

---
 src/util/permission.js          |    4 
 src/assets/img/key.png          |    0 
 src/views/Login1.vue            |  224 +++++++
 src/views/Admin/downLoadKey.vue |  110 +++
 src/router/index.js             |    8 
 src/views/Login.vue             |  128 +++
 src/views/Syunew3W.js           | 1374 ++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 1,837 insertions(+), 11 deletions(-)

diff --git a/src/assets/img/key.png b/src/assets/img/key.png
new file mode 100644
index 0000000..3a746f4
--- /dev/null
+++ b/src/assets/img/key.png
Binary files differ
diff --git a/src/router/index.js b/src/router/index.js
index d7648ea..f8e86ef 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -11,6 +11,13 @@
     component: () => import('@/views/Login'),
 	meta: { title: '登录' },
   },
+	{
+		path: '/downKey',
+		name: 'downKey',
+		component: () => import('@/views/Admin/downLoadKey.vue'),
+		meta: { title: '驱动下载' },
+		hidden:true
+	},
   {
     path: '/home',
     name: 'home',
@@ -148,6 +155,7 @@
 		// 	meta: { title: '菜单管理' },
 		// 	component: () => import('@/views/Admin/menuManage'),
 		// },
+
     ]
   },
 ];
diff --git a/src/util/permission.js b/src/util/permission.js
index acff799..782617a 100644
--- a/src/util/permission.js
+++ b/src/util/permission.js
@@ -11,10 +11,10 @@
     // 会再次进入路由跳转,next()方法没有参数是直接进入页面,不会再次进入路由拦截,有参数则会,因为跳转,
     // 所以再次进入路由,再次判断,再次进入路由,再次判断,循环往复无限循环
     // 所以一定要加to.path !== 'login'的判断
-    if (!token && to.path !== '/') {
+    if ((!token && to.path !== '/')&&(to.path==='downKey')) {
         message.error('用户信息已过期,请重新登录');
         next('/');
     }else {
         next();
     }
-});
\ No newline at end of file
+});
diff --git a/src/views/Admin/downLoadKey.vue b/src/views/Admin/downLoadKey.vue
new file mode 100644
index 0000000..ecf8722
--- /dev/null
+++ b/src/views/Admin/downLoadKey.vue
@@ -0,0 +1,110 @@
+<template>
+  <div class="key-box">
+    <div class="header">
+      <div class="title">
+        <div style="width: 300px;text-align: center">
+          自然灾害综合风险预警发布及响应联动系统
+        </div>
+        <div class="center"></div>
+        <span style="color: #96aec5;">驱动下载</span>
+      </div>
+    </div>
+    <div class="box-center">
+      <div style="width: 1200px;margin: 30px auto 0;padding: 0 20px 0;" v-for="(item,index) in state.keyTypes" :key="index">
+        <div class="title">{{item.name}}</div>
+        <a-card style="width: 250px;margin:20px 80px;" hoverable title="">
+          <template #extra>
+            <span style="cursor: pointer;color: #1890ff" @click="downLoad(item)">立即下载</span>
+          </template>
+          <template #cover>
+            <img
+                style="width: 120px;height: 120px;margin: 1px auto"
+                alt="example"
+                :src= keyPic
+            />
+          </template>
+          <template #actions>
+            <span>{{item.name}}驱动</span>
+          </template>
+        </a-card>
+      </div>
+
+    </div>
+  </div>
+</template>
+<script setup>
+import {reactive} from "vue";
+import { message } from 'ant-design-vue';
+import keyPic from '@/assets/img/key.png'
+
+const state = reactive({
+  keyTypes: [
+    {
+      name: 'Windows 版',
+      url: 'http://oss.bestong8.com/xinjiang/SetUp.exe'
+    },
+    {
+      name: 'Linux 版',
+      url: 'http://oss.bestong8.com/xinjiang/linux.zip'
+    },
+    {
+      name: 'Mac 版',
+      url: ''
+    },
+  ]
+})
+
+const downLoad = (item) => {
+  if(item.url === ''){
+    message.warning( "暂未开放苹果系统应用该加密工具。");
+  }else{
+    const link = document.createElement('a')
+    link.href =item.url
+    link.target = '_blank'
+    link.download = item.name + '.exe'
+    link.click()
+  }
+
+
+}
+
+</script>
+
+
+<style scoped lang="less">
+.key-box{
+  margin: 0 auto;
+  .header{
+    text-align: left;
+    width: 1200px;
+    margin: 30px auto;
+    .title{
+      display: flex;
+      align-items: center;
+      vertical-align: top;
+      font-size: 24px;
+
+      padding-left: 20px;
+      .center{
+        margin: 0 10px;
+        content: "";
+        height: 54px;
+        border-left: 2px solid #c7cddc;
+      }
+
+    }
+  }
+  .box-center{
+    padding-top: 20px;
+    padding-bottom: 20px;
+    min-width: 1200px;
+    .title{
+      font-size: 18px;
+      font-weight: 600;
+      border-bottom: 1px solid #d1d7e8;
+      padding: 10px 0;
+      margin-bottom: 6px;
+    }
+  }
+}
+</style>
diff --git a/src/views/Login.vue b/src/views/Login.vue
index b901080..7d00b20 100644
--- a/src/views/Login.vue
+++ b/src/views/Login.vue
@@ -83,7 +83,32 @@
         <a-checkbox :checked="saveAccount" style="color:#fff;" @change="isSave">记住密码</a-checkbox>
 <!--        <a style="float: right">忘记密码</a>-->
       </div>
-      <a-form-item style="text-align: center">
+      <div style="margin-bottom: 20px;height: auto;width: 100%;background-color: white;border-radius: 5px">
+        <div style="margin-left: 10px;display: flex;align-items: center;justify-content: space-between;padding: 0px 12px;">
+          <div v-if="keyMsg">
+            <a-icon style="color: lightcoral" type="exclamation-circle"/>
+            <span style="margin-left: 5px;line-height: 45px;font-size: 16px;color: lightcoral">{{keyMsg}}</span>
+          </div>
+          <div v-else>
+            <a-icon style="color: #52c41a" type="check-circle"/>
+            <span style="margin-left: 5px;line-height: 45px;font-size: 16px;color: #52c41a">加密证书检测成功</span>
+          </div>
+          <a-button
+              type="primary"
+              html-type="submit"
+              style="width: 20%;"
+              size="small"
+              @click="checkKey"
+          >
+            重新检测
+          </a-button>
+        </div>
+      </div>
+      <div style="margin-bottom: 20px;float: right;" >
+        <span style="color: #1890ff;cursor: pointer" @click="downLoadLKey">驱动下载</span>
+      </div>
+
+      <div style="text-align: center">
         <a-button
           type="primary"
           html-type="submit"
@@ -95,7 +120,7 @@
         >
           登录
         </a-button>
-      </a-form-item>
+      </div>
 	  <center><p>技术支持:技术保障部</p></center>
     </a-form-model>
   </div>
@@ -107,7 +132,7 @@
 import { login, getMenuAdmin } from "@/api/login";
 import Cookies from 'js-cookie';
 import {Base64} from "js-base64";
-
+import SoftKey3W from './Syunew3W.js'
 
 export default {
   name: "login",
@@ -119,13 +144,18 @@
       // form: this.$form.createForm(this),
       form: {
         name: '',
-        pwd: ''
+        pwd: '',
+        keyId:'',//锁id
+        keyUserName:'',//锁中的用户身份
+        returnEncData:'',//签名数据
+        rnd:"123"//随机字符
       },
       rules: {
         name: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
         pwd: [{ required: true, message: '请输入用户密码', trigger: 'blur' }]
       },
-      menu: []
+      menu: [],
+      keyMsg: '未检测到加密证书,请确保已连接',
     };
   },
   created() {
@@ -133,8 +163,18 @@
     //   this.form.validateFields();
     // });
     this.hasUserCodeOrPassword()
+    //检测key
+    this.checkKey()
   },
   methods: {
+    downLoadLKey () {
+      console.log('222')
+      const { href } = this.$router.resolve({
+        path: '/downKey'
+      })
+      window.open(href,'_blank')
+
+    },
     hasUserCodeOrPassword(){
       if (localStorage.getItem('userName') && localStorage.getItem('userPassword')) {
         this.form.name = localStorage.getItem('userName')
@@ -142,15 +182,85 @@
         this.saveAccount = true
       }
     },
+    async checkKey() {
+      let mSoftKey3A = new SoftKey3W();//注意,由于USB的操作是异步的,所以所有函数的调用前必须加await !!!!!!!!!
+      let DevicePath = await mSoftKey3A.FindPort(1);//'查找是否存在多把加密锁
+      if (mSoftKey3A.GetLastError() == 0) {
+        this.keyMsg = "系统发现有2把及以上的加密证书"
+        return false
+      }
+      DevicePath = await mSoftKey3A.FindPort(0);//'查找是否存在加密锁
+      if (mSoftKey3A.GetLastError() != 0) {
+        this.keyMsg = "未检测到加密证书,请确保已连接"
+        return false
+      }
+      this.keyMsg = ""
+    },
 
     isSave(e){
       const t = this
       t.saveAccount = !t.saveAccount
     },
+    async checkUsbkeyData(){
+      let mSoftKey3A = new SoftKey3W();//注意,由于USB的操作是异步的,所以所有函数的调用前必须加await !!!!!!!!!
+      let DevicePath = await mSoftKey3A.FindPort(1);//'查找是否存在多把加密锁
+      console.log(mSoftKey3A,'mSoftKey3A')
+      if (mSoftKey3A.GetLastError() == 0) {
+        this.keyMsg = "系统发现有2把及以上的加密证书"
+        this.$message.warning( "系统发现有2把及以上的加密证书");
+        return false
+      }
+      DevicePath = await mSoftKey3A.FindPort(0);//'查找是否存在加密锁
+      if (mSoftKey3A.GetLastError() != 0) {
+        this.keyMsg = "未检测到加密证书,请确保已连接"
+        this.$message.warning( "未检测到加密证书,请确保已连接");
+        return false
+      }
+      console.log(DevicePath,'devpathhh')
+      //'读取锁的唯一ID
+      this.form.keyId=await mSoftKey3A.GetChipID(DevicePath);
 
-    handleSubmit() {
+      if( mSoftKey3A.GetLastError()!= 0 )
+      {
+          this.$message.warning("返回芯片唯一ID时出现错误,错误码为:"+mSoftKey3A.GetLastError().toString())
+          return false
+      }
+      console.log(this.form.keyId,'this.form.keyId')
+      //从锁中取出用户身份,与签名后的数据一并送到服务端进行验证。以验证用户身份
+      this.form.keyUserName=await mSoftKey3A.GetSm2UserName(DevicePath);
+
+      if( mSoftKey3A.GetLastError()!= 0 )
+      {
+        this.$message.warning( "返回用户身份时出现错误,错误码为:"+mSoftKey3A.GetLastError().toString());
+        return false
+      }
+      console.log(this.form.keyUserName,'this.form.keyUserName')
+      //使用默认的PIN码
+      var Pin="123"
+      //这里使用锁中的私钥对身份-用户名及消息-随机数的进行数字签名,使用默认的PIN码,返回签名后的数据
+      this.form.rnd=String(parseInt(Math.random()*(65536+1),10));
+      this.form.returnEncData=await mSoftKey3A.YtSign(this.form.rnd,Pin,DevicePath);
+      if( mSoftKey3A.GetLastError()!= 0 )
+      {
+        this.$message.warning( "进行签名时出现错误,错误码为:"+mSoftKey3A.GetLastError().toString());
+          return false
+      }
+      if(this.form.name!=this.form.keyUserName){
+        this.$message.warning( "用户身份不一致,无法登陆");
+        return false
+      }
+      console.log(this.form.returnEncData,'this.form.returnEncData')
+      console.log(this.form,'this.form')
+      return true
+    },
+
+    async handleSubmit() {
       this.$refs.ruleForm.validate(async (valid) => {
         if (valid) {
+          let checkUsb=await this.checkUsbkeyData()
+          if(!checkUsb){
+            return
+          }
           this.isLoading = true
           const res = await login(this.form)
           if (res.data.code === 100) {
@@ -211,11 +321,11 @@
 	h1{font-size: 48px;color:#fff;}
 	}
 .login {
-  
+
   .login-form {
     width: 400px;
-    margin: 60px auto 0px;	
-	
+    margin: 60px auto 0px;
+
   }
 }
 .ant-tabs{
diff --git a/src/views/Login1.vue b/src/views/Login1.vue
new file mode 100644
index 0000000..b901080
--- /dev/null
+++ b/src/views/Login1.vue
@@ -0,0 +1,224 @@
+<template>
+	<div class='bd'>
+	<div class="hedaer">
+	  <h2>新疆维吾尔自治区自然灾害综合监测预警中心</h2>
+	  <h1>自然灾害综合风险预警发布及响应联动系统</h1>
+	</div>
+  <div class="login">
+
+    <a-form-model
+      layout="horizontal"
+      :model="form"
+      ref="ruleForm"
+      :rules="rules"
+      class="login-form"
+    >
+      <a-form-model-item ref="name" prop="name">
+        <a-input
+            placeholder="请输入用户名"
+            size="large"
+            v-model="form.name"
+            autocomplete="new-password"
+        >
+          <a-icon slot="prefix" type="user" style="color:rgba(0,0,0,.25)" />
+        </a-input>
+      </a-form-model-item>
+      <a-form-model-item ref="pwd" prop="pwd">
+        <a-input-password
+            type="password"
+            placeholder="请输入密码"
+            size="large"
+            v-model="form.pwd"
+            autocomplete="new-password"
+        >
+          <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
+        </a-input-password>
+      </a-form-model-item>
+<!--      <a-tabs default-active-key="1" @change="callback">-->
+<!--        <a-tab-pane key="1" tab="用户名登录">-->
+<!--          <a-form-item>-->
+<!--            <a-input-->
+<!--              placeholder="请输入用户"-->
+<!--              size="large"-->
+<!--              v-model="form.name"-->
+<!--            >-->
+<!--              <a-icon slot="prefix" type="user" style="color:rgba(0,0,0,.25)" />-->
+<!--            </a-input>-->
+<!--          </a-form-item>-->
+<!--          <a-form-item>-->
+<!--            <a-input-password-->
+<!--              type="password"-->
+<!--              placeholder="请输入密码"-->
+<!--              size="large"-->
+<!--              v-model="form.pwd"-->
+<!--            >-->
+<!--              <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />-->
+<!--            </a-input-password>-->
+<!--          </a-form-item>-->
+<!--        </a-tab-pane>-->
+<!--        <a-tab-pane key="2" tab="验证码登录" force-render>-->
+<!--          <a-form-item>-->
+<!--            <a-input-->
+<!--              placeholder="手机号"-->
+<!--              size="large"-->
+<!--            >-->
+<!--              <a-icon slot="prefix" type="mobile" style="color:rgba(0,0,0,.25)" />-->
+<!--            </a-input>-->
+<!--          </a-form-item>-->
+<!--          <a-form-item>-->
+<!--            <a-row :gutter="8">-->
+<!--              <a-col :span="17">-->
+<!--                <a-input placeholder="验证码">-->
+<!--                  <a-icon slot="prefix" type="mobile" style="color:rgba(0,0,0,.25)" />-->
+<!--                </a-input>-->
+<!--              </a-col>-->
+<!--              <a-col :span="7">-->
+<!--                <a-button style="width: 100%">获取验证码</a-button>-->
+<!--              </a-col>-->
+<!--            </a-row>-->
+<!--          </a-form-item>-->
+<!--        </a-tab-pane>-->
+<!--      </a-tabs>-->
+      <div style="margin-bottom: 20px">
+        <a-checkbox :checked="saveAccount" style="color:#fff;" @change="isSave">记住密码</a-checkbox>
+<!--        <a style="float: right">忘记密码</a>-->
+      </div>
+      <a-form-item style="text-align: center">
+        <a-button
+          type="primary"
+          html-type="submit"
+          style="width: 100%"
+          size="large"
+          @click="handleSubmit"
+          :loading="isLoading"
+          v-preventReClick="1500"
+        >
+          登录
+        </a-button>
+      </a-form-item>
+	  <center><p>技术支持:技术保障部</p></center>
+    </a-form-model>
+  </div>
+  </div>
+</template>
+
+<script>
+
+import { login, getMenuAdmin } from "@/api/login";
+import Cookies from 'js-cookie';
+import {Base64} from "js-base64";
+
+
+export default {
+  name: "login",
+  data() {
+    return {
+      isLoading: false,
+      saveAccount: false,
+      // hasErrors,
+      // form: this.$form.createForm(this),
+      form: {
+        name: '',
+        pwd: ''
+      },
+      rules: {
+        name: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
+        pwd: [{ required: true, message: '请输入用户密码', trigger: 'blur' }]
+      },
+      menu: []
+    };
+  },
+  created() {
+    // this.$nextTick(() => {
+    //   this.form.validateFields();
+    // });
+    this.hasUserCodeOrPassword()
+  },
+  methods: {
+    hasUserCodeOrPassword(){
+      if (localStorage.getItem('userName') && localStorage.getItem('userPassword')) {
+        this.form.name = localStorage.getItem('userName')
+        this.form.pwd = Base64.decode(localStorage.getItem('userPassword'))//解密
+        this.saveAccount = true
+      }
+    },
+
+    isSave(e){
+      const t = this
+      t.saveAccount = !t.saveAccount
+    },
+
+    handleSubmit() {
+      this.$refs.ruleForm.validate(async (valid) => {
+        if (valid) {
+          this.isLoading = true
+          const res = await login(this.form)
+          if (res.data.code === 100) {
+            Cookies.set('resTk', res.data.data.tk);
+            Cookies.set('resUid', res.data.data.uid);
+            Cookies.set('userInfo',JSON.stringify(res.data.data),{expires: 7})
+            if (this.saveAccount) {
+              localStorage.setItem('userName', this.form.name)
+              localStorage.setItem('userPassword', Base64.encode(this.form.pwd))
+            } else {
+              localStorage.removeItem('userName')
+              localStorage.removeItem('userPassword')
+            }
+            this.$router.push('/home')
+          } else {
+            this.$message.warning(res.data.msg);
+          }
+          this.isLoading = false
+        } else {
+          console.log('error submit!!');
+          return false;
+        }
+      });
+    },
+
+  },
+};
+</script>
+
+<style lang="less" scoped>
+	p{
+		color:#fff;
+		margin-top: 55px;
+	}
+h2{
+	font-size: 30px;
+}
+.bd {
+	width: 100%;
+	height: 100vh;
+	background: url('../assets/img/bg.jpeg') no-repeat;
+	background-size: 100% 100%;
+	background-attachment: fixed;/* 不设置的话页面滑动时,背景会不铺满*/
+}
+
+
+/deep/ .ant-tabs-bar {
+  border-bottom: 0px;
+  text-align: center;
+}
+  .hedaer {
+    margin: 0px auto;
+	padding-top:200px;
+    width: 1000px;
+    text-align: center;
+	text-shadow:0 0 1px #000;
+	h2{font-size: 36px;color:#fff;}
+	h1{font-size: 48px;color:#fff;}
+	}
+.login {
+  
+  .login-form {
+    width: 400px;
+    margin: 60px auto 0px;	
+	
+  }
+}
+.ant-tabs{
+	color:#fff;
+	}
+</style>
diff --git a/src/views/Syunew3W.js b/src/views/Syunew3W.js
new file mode 100644
index 0000000..56c195a
--- /dev/null
+++ b/src/views/Syunew3W.js
@@ -0,0 +1,1374 @@
+
+ export default class  SoftKey3W
+{
+    static  Socket_UK;
+    static url;
+    static LastError
+    constructor() {
+    
+        var isIE11 = navigator.userAgent.indexOf('Trident') > -1 && navigator.userAgent.indexOf("rv:11.0") > -1;
+        var isEDGE= navigator.userAgent.indexOf("Edge") > -1;
+        var u = document.URL;
+        if (u.substring(0, 5) == "https") {
+            if(isIE11 || isEDGE)
+    	    {
+    		 if(isIE11)this.url = "wss://127.0.0.1:4006/xxx"; else url = "ws://127.0.0.1:4006/xxx";
+    	    }
+            else
+            {
+                    this.url = "ws://localhost:4006/xxx";
+                }
+            } else {
+                this.url = "ws://127.0.0.1:4006/xxx";
+            }
+          
+        if (typeof MozWebSocket != "undefined") {
+            this.Socket_UK = new MozWebSocket(this.url,"usbkey-protocol");
+        } else {
+            this.Socket_UK = new WebSocket(this.url,"usbkey-protocol");
+        }   
+        this.Socket_UK.onerror = (event) => {
+            alert('未能连接服务程序,请确定服务程序是否安装。');
+        };     
+        SoftKey3W.LastError=0     
+    }
+  
+   _FindPort = function (UK,start) 
+    { 
+        var msg = 
+        {
+            FunName: "FindPort",
+            start: start
+        };
+        UK.send(JSON.stringify(msg));
+   };   
+    
+    _FindPort_2 = function (UK,start, in_data , verf_data)
+    { 
+         var msg = 
+        {
+            FunName: "FindPort_2",
+            start: start,
+            in_data: in_data,
+            verf_data:verf_data
+        };
+        UK.send(JSON.stringify(msg)); 
+    }; 
+    
+    _FindPort_3 = function (UK,start,in_data,verf_data)
+    { 
+        var msg = 
+        {
+            FunName: "FindPort_3",
+            start: start,
+            in_data: in_data,
+            verf_data:verf_data
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _GetVersion = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetVersion",
+            Path: Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _GetVersionEx = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetVersionEx",
+            Path: Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _GetID_1 = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetID_1",
+            Path: Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _GetID_2 = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetID_2",
+            Path: Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    
+    _sRead = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "sRead",
+            Path: Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _sWrite = function (UK,InData, Path)
+    { 
+         var msg = 
+        {
+            FunName: "sWrite",
+            InData: InData,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg)); 
+    }; 
+    
+    _sWrite_2 = function (UK,InData, Path)
+    { 
+        var msg = 
+        {
+            FunName: "sWrite_2",
+            InData: InData,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _sWrite_2Ex = function (UK,InData,Path)
+    { 
+        var msg = 
+        {
+            FunName: "sWrite_2Ex",
+            InData: InData,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _sWriteEx = function (UK,InData,Path)
+    { 
+        var msg = 
+        {
+            FunName: "sWriteEx",
+            InData: InData,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _sWriteEx_New = function (UK,InData,Path)
+    { 
+        var msg = 
+        {
+            FunName: "sWriteEx_New",
+            InData: InData,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _sWrite_2Ex_New = function (UK,InData,Path)
+    { 
+        var msg = 
+        {
+            FunName: "sWrite_2Ex_New",
+            InData: InData,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    
+     _YRead= function(Address,HKey,LKey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YRead",
+            Address:Address,
+            HKey:HKey,
+            LKey:LKey,
+            Path:Path
+        };
+        Socket_UK.send(JSON.stringify(msg));
+    };   
+    
+    _YWrite= function(InData,Address,HKey,LKey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YWrite",
+            InData:InData,
+            Address:Address,
+            HKey:HKey,
+            LKey:LKey,
+            Path:Path
+        };
+        Socket_UK.send(JSON.stringify(msg));
+    };   
+    
+    
+    static _SetBuf= function(UK,InData,pos)
+    { 
+        var msg = 
+        {
+            FunName: "SetBuf",
+            InData: InData,
+            pos:pos
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static _GetBuf= function(UK,pos)
+    { 
+        var msg = 
+        {
+            FunName: "GetBuf",
+            pos: pos
+        };
+        UK.send(JSON.stringify(msg));
+    };     
+    
+    static _YReadEx= function(UK,Address,len, HKey,LKey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YReadEx",
+            Address:Address,
+            len:len,
+            HKey:HKey,
+            LKey:LKey,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static _YWriteEx= function (UK,Address,len,HKey,LKey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YWriteEx",
+            Address:Address,
+            len:len,
+            HKey:HKey,
+            LKey:LKey,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _YReadString = function (UK,Address,len,HKey,LKey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YReadString",
+            Address:Address,
+            len:len,
+            HKey:HKey,
+            LKey:LKey,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _YWriteString = function (UK,InString,Address,HKey,LKey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YWriteString",
+            InString:InString,
+            Address:Address,
+            HKey:HKey,
+            LKey:LKey,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _SetWritePassword = function (UK,W_Hkey,W_Lkey,new_Hkey,new_Lkey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SetWritePassword",
+            W_Hkey:W_Hkey,
+            W_Lkey:W_Lkey,
+            new_Hkey:new_Hkey,
+            new_Lkey:new_Lkey,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _SetReadPassword = function (UK,W_Hkey,W_Lkey,new_Hkey,new_Lkey,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SetReadPassword",
+            W_Hkey:W_Hkey,
+            W_Lkey:W_Lkey,
+            new_Hkey:new_Hkey,
+            new_Lkey:new_Lkey,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+     
+    _DecString = function (UK,InString,Key)
+    { 
+        var msg = 
+        {
+            FunName: "DecString",
+            InString:InString,
+            Key:Key
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _EncString = function (UK,InString,Path)
+    { 
+        var msg = 
+        {
+            FunName: "EncString",
+            InString:InString,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _EncString_New = function (UK,InString,Path)
+    { 
+        var msg = 
+        {
+            FunName: "EncString_New",
+            InString:InString,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _Cal = function(UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "Cal",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _Cal_New = function(UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "Cal_New",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };  
+    
+    _GetProduceDate= function(UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetProduceDate",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };  
+    
+    _SetID= function(UK,Seed,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SetID",
+            Seed:Seed,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _SetCal_2 = function (UK,Key,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SetCal_2",
+            Key:Key,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };    
+    
+    _SetCal_2 = function (UK,Key,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SetCal_2",
+            Key:Key,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _SetCal_New = function (UK,Key,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SetCal_New",
+            Key:Key,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static _SetEncBuf= function(UK,InData,pos)
+    { 
+        var msg = 
+        {
+            FunName: "SetEncBuf",
+            InData:InData,
+            pos: pos
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static _GetEncBuf= function(UK,pos)
+    { 
+        var msg = 
+        {
+            FunName: "GetEncBuf",
+            pos: pos
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+
+    _ReSet = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "ReSet",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };     
+    
+    _MacAddr = function (UK)
+    { 
+        var msg = 
+        {
+            FunName: "MacAddr"
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    
+    _GetChipID = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetChipID",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static _StarGenKeyPair= function(UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "StarGenKeyPair",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static _GenPubKeyY= function(UK)
+    { 
+        var msg = 
+        {
+            FunName: "GenPubKeyY"
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static _GenPubKeyX= function(UK)
+    { 
+        var msg = 
+        {
+            FunName: "GenPubKeyX"
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    static  _GenPriKey= function(UK)
+    { 
+        var msg = 
+        {
+            FunName: "GenPriKey"
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _GetPubKeyY = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetPubKeyY",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _GetPubKeyX = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetPubKeyX",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _GetSm2UserName = function (UK,Path)
+    { 
+        var msg = 
+        {
+            FunName: "GetSm2UserName",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _Set_SM2_KeyPair = function (UK,PriKey,PubKeyX,PubKeyY,sm2UserName,Path )
+    { 
+        var msg = 
+        {
+            FunName: "Set_SM2_KeyPair",
+            PriKey:PriKey,
+            PubKeyX:PubKeyX,
+            PubKeyY:PubKeyY,
+            sm2UserName:sm2UserName,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _YtSign = function (UK,SignMsg,Pin,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YtSign",
+            SignMsg:SignMsg,
+            Pin:Pin,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _YtSign_2 = function (UK,SignMsg,Pin,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YtSign_2",
+            SignMsg:SignMsg,
+            Pin:Pin,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _YtVerfiy = function (UK,id,SignMsg,PubKeyX, PubKeyY,VerfiySign,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YtVerfiy",
+            id:id,
+            SignMsg:SignMsg,
+            PubKeyX:PubKeyX,
+            PubKeyY:PubKeyY,
+            VerfiySign:VerfiySign,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _SM2_DecString = function (UK,InString,Pin,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SM2_DecString",
+            InString:InString,
+            Pin:Pin,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _SM2_EncString = function (UK,InString,Path)
+    { 
+        var msg = 
+        {
+            FunName: "SM2_EncString",
+            InString:InString,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+    _YtSetPin = function (UK,OldPin,NewPin,Path)
+    { 
+        var msg = 
+        {
+            FunName: "YtSetPin",
+            OldPin:OldPin,
+            NewPin:NewPin,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+	_FindU = function (UK,start)
+	{ 
+        var msg = 
+        {
+            FunName: "FindU",
+            start: start
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+	_FindU_2 = function (UK,start,in_data,verf_data)
+	{ 
+        var msg = 
+        {
+            FunName: "FindU_2",
+            start: start,
+            in_data: in_data,
+            verf_data:verf_data
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+	_FindU_3 = function (UK,start,in_data,verf_data)
+	{ 
+        var msg = 
+        {
+            FunName: "FindU_3",
+            start: start,
+            in_data: in_data,
+            verf_data:verf_data
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+	_IsUReadOnly = function (UK,Path)
+	{ 
+        var msg = 
+        {
+            FunName: "IsUReadOnly",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+	_SetUReadOnly = function (UK,Path)
+	{ 
+        var msg = 
+        {
+            FunName: "SetUReadOnly",
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+	_SetHidOnly = function (UK,IsHidOnly,Path)
+	{ 
+        var msg = 
+        {
+            FunName: "SetHidOnly",
+            IsHidOnly:IsHidOnly,
+            Path:Path
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+    
+   static ResetOrder= function(UK) 
+    {
+		 var msg = 
+        {
+            FunName: "ResetOrder"
+        };
+         UK.send(JSON.stringify(msg));
+	 } 
+	 
+	ContinueOrder = function (UK) 
+    {
+		 var msg = 
+        {
+            FunName: "ContinueOrder"
+        };
+         UK.send(JSON.stringify(msg));
+     } 
+     
+     
+     _ComputerName= function(UK)
+    { 
+        var msg = 
+        {
+            FunName: "ComputerName"
+        };
+        UK.send(JSON.stringify(msg));
+    };   
+     
+
+	 
+	 SendCmdAndWait = function(IsReturnErr,fun,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10) 
+{
+ var UK;
+ 
+   return new Promise((resolve, reject) => {   
+
+    if (typeof MozWebSocket != "undefined") {
+	   UK = new MozWebSocket(this.url,"usbkey-protocol");
+	} else {
+		UK = new WebSocket(this.url,"usbkey-protocol");
+	}
+  
+	 try
+	 {
+	      UK.onopen = function() {
+            SoftKey3W.ResetOrder(UK);//
+	    } 
+		    
+	    UK.onmessage =function got_packet(Msg) 
+	    {
+	        var UK_Data = JSON.parse(Msg.data);
+	        var return_value;
+	        if(UK_Data.type!="Process")return ;//
+	        switch(UK_Data.order) 
+	        {
+	            case 0:
+	                {
+	                  fun(UK,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10); 
+	                }
+	                break; //!!!!!
+	            case 1:
+	                {
+	                    SoftKey3W.LastError=UK_Data.LastError;
+	                    return_value=UK_Data.return_value;
+	                    if( SoftKey3W.LastError!=0){
+	                       if(IsReturnErr)return_value=SoftKey3W.LastError;
+	                     } 
+	                     //
+						 UK.close();
+						 
+						 resolve(return_value);
+	                }
+	                break;
+            }
+	    } 
+	    UK.onclose = function(){
+
+	    }
+        UK.onerror = (event) => {
+            alert('未能连接服务程序,请确定服务程序是否安装。');
+        };
+	  }
+	 catch(e)  
+	  {  
+				alert(e.name + ": " + e.message);
+				 resolve(false);
+	  }  
+	}) 
+}
+
+    GetLastError = function()
+    {
+        return SoftKey3W.LastError;
+    }
+
+    FindPort = function(start) 
+    { 
+        return this.SendCmdAndWait(false,this._FindPort,start);
+    }
+    
+    FindPort_2= function( start,in_data,  verf_data )
+    {
+       return this.SendCmdAndWait(false,this._FindPort_2,start,in_data,  verf_data);
+    };
+
+    GetVersionEx= function(KeyPath)
+    {
+         return this.SendCmdAndWait(false,this._GetVersionEx,KeyPath);
+    };
+
+    GetVersion= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._GetVersion,KeyPath); 
+    };
+
+ 	
+
+    GetID_1= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._GetID_1,KeyPath);
+    }
+
+    GetID_2= function(KeyPath)
+    {
+       return this.SendCmdAndWait(false,this._GetID_2,KeyPath);
+
+    }
+ 	
+    GetChipID= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._GetChipID,KeyPath);
+        
+    };
+
+    SetWritePassword= function( W_HKey,  W_LKey,  new_HKey,  new_LKey,KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetWritePassword, W_HKey,  W_LKey,  new_HKey,  new_LKey,KeyPath);
+    }
+
+    SetReadPassword= function( W_HKey,  W_LKey,  new_HKey,  new_LKey,KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetReadPassword,W_HKey,  W_LKey,  new_HKey,  new_LKey,KeyPath);
+    }
+
+
+    SetCal_2= function( Key,KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetCal_2,Key,KeyPath);
+    }
+
+    SetCal_New= function(Key,KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetCal_New,Key,KeyPath);
+    }
+
+
+    EncString= function( InString,KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._EncString,InString,KeyPath);
+    }
+
+    EncString_New= function( InString,KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._EncString_New, InString,KeyPath);
+    }
+
+
+
+    Cal= function(Inbuf,KeyPath)
+    {
+        return SubCal(_Cal,Inbuf,KeyPath);
+    }
+
+    Cal_New= function(Inbuf,KeyPath)
+    {
+       return SubCal(_Cal_New,Inbuf,KeyPath)
+    }
+
+
+
+    sWriteEx= function( in_data ,KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._sWriteEx,in_data ,KeyPath);
+    }
+
+    sWrite_2Ex= function( in_data ,KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._sWrite_2Ex,in_data ,KeyPath);
+    }
+
+    sWriteEx_New= function( in_data ,KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._sWriteEx_New,in_data ,KeyPath);
+    }
+
+    sWrite_2Ex_New= function( in_data ,KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._sWrite_2Ex_New,in_data ,KeyPath);
+    }
+
+    sWrite= function( in_data ,KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._sWrite,in_data ,KeyPath);
+    }
+
+    sWrite_2= function( in_data ,KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._sWrite_2,in_data ,KeyPath);
+    }
+
+    sRead= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._sRead,KeyPath);
+    }
+
+  
+     YWriteEx = function(indata,   address,  nlen,  HKey,  LKey,KeyPath) 
+    {
+        var UK;
+        
+       return new Promise((resolve, reject) => {   
+
+        if (typeof MozWebSocket != "undefined") {
+	       UK = new MozWebSocket(this.url,"usbkey-protocol");
+	    } else {
+		    UK = new WebSocket(this.url,"usbkey-protocol");
+	    }
+
+	     try
+	     {
+	        var i=0,order;
+	          UK.onopen = function() {
+                SoftKey3W.ResetOrder(UK);//
+    	   	  
+	        } 
+    		    
+	        UK.onmessage =function got_packet(Msg) 
+	        {
+	            var UK_Data = JSON.parse(Msg.data);
+	            var return_value;
+	            if(UK_Data.type!="Process")return ;//
+	            if(UK_Data.order<nlen)
+	            {
+                    SoftKey3W._SetBuf(UK,indata[UK_Data.order],UK_Data.order);
+	              return;
+	            }
+	           else{
+	              order=UK_Data.order-nlen;
+	           }
+	            
+	            switch(order) 
+	            {
+	                case 0:
+	                    {
+	                       SoftKey3W.LastError=UK_Data.LastError;
+	                      if( SoftKey3W.LastError!=0){ UK.close();resolve(UK_Data.return_value);return ;  } 
+	                      SoftKey3W._YWriteEx(UK,address,  nlen,  HKey,  LKey,KeyPath); 
+	                    }
+	                    break; //!!!!!
+	                case 1:
+	                    {
+	                        SoftKey3W.LastError=UK_Data.LastError;
+	                        return_value=UK_Data.return_value;
+	                        if( SoftKey3W.LastError!=0){
+	                           return_value=SoftKey3W.LastError;
+	                         } 
+	                         
+						     UK.close();
+    						 
+						     resolve(return_value);
+	                    }
+	                    break;
+                }
+	        } 
+	        UK.onclose = function(){
+
+	        }
+            UK.onerror = (event) => {
+                alert('未能连接服务程序,请确定服务程序是否安装。');
+            };
+	      }
+	     catch(e)  
+	      {  
+				    alert(e.name + ": " + e.message);
+				     resolve(false);
+	      }  
+	    }) 
+}
+    
+
+    YWriteString= function(InString,Address , HKey,  LKey,KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._YWriteString,InString,Address , HKey,  LKey,KeyPath);
+    }
+
+    YReadEx= function(address,  nlen,  HKey,  LKey,KeyPath )
+    {  
+        var outb = new Uint8Array(nlen);
+          var UK;
+       return new Promise((resolve, reject) => {   
+
+        if (typeof MozWebSocket != "undefined") {
+	       UK = new MozWebSocket(this.url,"usbkey-protocol");
+	    } else {
+		    UK = new WebSocket(this.url,"usbkey-protocol");
+	    }
+
+	     try
+	     {
+	        var i,order;
+	          UK.onopen = function() {
+                SoftKey3W.ResetOrder(UK);//
+    	   	  
+	        } 
+    		    
+	        UK.onmessage =function got_packet(Msg) 
+	        {
+	            var UK_Data = JSON.parse(Msg.data);
+	            var return_value;
+	            if(UK_Data.type!="Process")return ;//
+	           if(UK_Data.order<2)
+	           {
+	           
+	                switch(UK_Data.order) 
+	                {
+	                    case 0:
+	                        {
+                                SoftKey3W._YReadEx(UK,address,  nlen,  HKey,  LKey,KeyPath); 
+	                        }
+	                        break; //!!!!!
+	                    case 1:
+	                        {
+	                            SoftKey3W.LastError=UK_Data.LastError;
+	                            if( SoftKey3W.LastError!=0){ UK.close();resolve(outb);return ;  } 
+						           
+						          i=0;
+						          SoftKey3W._GetBuf(UK,i);//
+	                        }
+	                        break;
+                    }
+                  }
+                  else{
+                    SoftKey3W.LastError=UK_Data.LastError;
+	                  if( SoftKey3W.LastError!=0){ UK.close();resolve(outb);return ;  } 
+                      outb[i]=UK_Data.return_value;
+                      i++;
+                      if( UK_Data.LastError!=0 || i>=nlen)
+                      {
+                         UK.close();resolve(outb);return ;
+                      }
+                      SoftKey3W._GetBuf(UK,i);//
+                      
+                  }
+	        } 
+	        UK.onclose = function(){
+
+	        }
+            UK.onerror = (event) => {
+                alert('未能连接服务程序,请确定服务程序是否安装。');
+            };
+	      }
+	     catch(e)  
+	      {  
+				    alert(e.name + ": " + e.message);
+				     resolve(false);
+	      }  
+	    }) 
+		return outb;
+    }
+
+    YReadString= function( Address,  nlen, HKey,  LKey,KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._YReadString,Address,  nlen, HKey,  LKey,KeyPath);
+    }
+
+
+    YRead= function(Address,HKey,LKey,Path)
+    { 
+        return this.SendCmdAndWait(false,this._YRead,Address,HKey,LKey,Path);
+    };   
+    
+    YWrite= function(InData,Address,HKey,LKey,Path)
+    { 
+         return this.SendCmdAndWait(true,this._YWrite,InData,Address,HKey,LKey,Path)
+    };   
+
+
+    ReSet= function( KeyPath )
+    {
+        return this.SendCmdAndWait(true,this._ReSet,KeyPath);
+    }
+
+
+    SetCal= function( HKey,  LKey,  new_HKey, new_LKey,  KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetCal,HKey,  LKey,  new_HKey, new_LKey,KeyPath);
+    }
+
+
+
+    SetID= function( Seed, KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetID, Seed,KeyPath);
+    }
+
+    GetProduceDate= function( KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._GetProduceDate,KeyPath);
+    }
+
+    SetHidOnly= function( IsHidOnly, KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetHidOnly, IsHidOnly,KeyPath);
+    }
+
+
+    SetUReadOnly= function(KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SetUReadOnly,KeyPath);
+    }
+    
+    
+     StarGenKeyPair = function(KeyPath) 
+    {
+     var KeyPairInfo={
+            GenPriKey:"",
+            GenPubKeyX:"",
+            GenPubKeyY:"",
+        } 
+     var UK;
+     
+       return new Promise((resolve, reject) => {   
+
+        if (typeof MozWebSocket != "undefined") {
+	       UK = new MozWebSocket(this.url,"usbkey-protocol");
+	    } else {
+		    UK = new WebSocket(this.url,"usbkey-protocol");
+	    }
+	     try
+	     {
+	          UK.onopen = function() {
+                SoftKey3W.ResetOrder(UK);//
+	        } 
+    		    
+	        UK.onmessage =function got_packet(Msg) 
+	        {
+	            var UK_Data = JSON.parse(Msg.data);
+	            var return_value;
+	            if(UK_Data.type!="Process")return ;//
+	            switch(UK_Data.order) 
+	            {
+	                case 0:
+	                    {
+                            SoftKey3W._StarGenKeyPair(UK,KeyPath); 
+	                    }
+	                    break; //
+	                case 1:
+	                    {
+	                        SoftKey3W.LastError=UK_Data.LastError;
+	                        if( SoftKey3W.LastError!=0){UK.close();  resolve(KeyPairInfo);return ;}
+                            SoftKey3W._GenPriKey(UK);
+	                }
+	                break;	
+                    case 2:
+	                    {
+	                         SoftKey3W.LastError=UK_Data.LastError;
+	                        if( SoftKey3W.LastError!=0){UK.close();  resolve(KeyPairInfo);return ;}
+                            KeyPairInfo.GenPriKey=UK_Data.return_value;
+	                        SoftKey3W._GenPubKeyX(UK);
+	                    }
+	                    break;	
+                    case 3:
+	                    {
+	                         SoftKey3W.LastError=UK_Data.LastError;
+	                        if( SoftKey3W.LastError!=0){UK.close();  resolve(KeyPairInfo);return ;} 
+	                        KeyPairInfo.GenPubKeyX=UK_Data.return_value;
+	                        SoftKey3W._GenPubKeyY(UK);
+	                    }
+	                    break;	
+	                  case 4:
+	                    {
+	                         SoftKey3W.LastError=UK_Data.LastError;
+	                        if( SoftKey3W.LastError!=0){UK.close();  resolve(KeyPairInfo);return ;} 
+	                        KeyPairInfo.GenPubKeyY=UK_Data.return_value;
+    	                    
+	                        UK.close();  resolve(KeyPairInfo);return ;
+	                    }
+	                    break;
+                    }
+	        } 
+	        UK.onclose = function(){
+
+	        }
+            UK.onerror = (event) => {
+                alert('未能连接服务程序,请确定服务程序是否安装。');
+            };
+	      }
+	     catch(e)  
+	      {  
+				    alert(e.name + ": " + e.message);
+				     resolve(false);
+	      }  
+	    }) 
+    }
+
+    
+
+    Set_SM2_KeyPair= function(PriKey, PubKeyX, PubKeyY, SM2_UserName, KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._Set_SM2_KeyPair,PriKey, PubKeyX, PubKeyY, SM2_UserName,KeyPath);
+    }
+
+    Get_SM2_PubKey= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._Get_SM2_PubKey,KeyPath);
+    }
+
+    GetPubKeyX= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._GetPubKeyX,KeyPath);
+    }
+
+    GetPubKeyY= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._GetPubKeyY,KeyPath);
+    }
+
+    GetSm2UserName= function(KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._GetSm2UserName,KeyPath);
+    }
+
+    SM2_EncBuf= function( InBuf, inlen, KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SM2_EncBuf, InBuf, inlen,KeyPath);
+    }
+
+    SM2_DecBuf= function( InBuf, inlen, pin, KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._SM2_DecBuf,InBuf, inlen, pin, KeyPath);
+    }
+
+    SM2_EncString= function(InString,  KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._SM2_EncString,InString, KeyPath);
+    }
+
+    SM2_DecString= function(InString,  pin, KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._SM2_DecString,InString,  pin,KeyPath);
+    }
+
+    YtSetPin= function(old_pin, new_pin, KeyPath)
+    {
+        return this.SendCmdAndWait(true,this._YtSetPin,old_pin, new_pin, KeyPath);
+    }
+
+
+    YtSign= function(msg,  pin,  KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._YtSign,msg,  pin,  KeyPath);
+    }
+
+    YtSign_2= function(msg,  pin,  KeyPath)
+    {
+        return this.SendCmdAndWait(false,this._YtSign_2,msg,  pin,  KeyPath);
+    }
+
+    MacAddr= function()
+    {
+        return this.SendCmdAndWait(false,this._MacAddr);
+    }
+    
+    ComputerName= function()
+    { 
+       return this.SendCmdAndWait(false,this._ComputerName);
+    }; 
+    
+       SubCal = function(Fun,Inbuf,KeyPath) 
+    {
+        var UK;var outb = new Uint8Array(8);
+       return new Promise((resolve, reject) => {   
+
+        if (typeof MozWebSocket != "undefined") {
+	       UK = new MozWebSocket(this.url,"usbkey-protocol");
+	    } else {
+		    UK = new WebSocket(this.url,"usbkey-protocol");
+	    }
+
+	     try
+	     {
+	        var i=0,order;var bIsEnc=true;
+	          UK.onopen = function() {
+                SoftKey3W.ResetOrder(UK);//
+    	   	  
+	        } 
+    		    
+	        UK.onmessage =function got_packet(Msg) 
+	        {
+	            var UK_Data = JSON.parse(Msg.data);
+	            var return_value;
+	            if(UK_Data.type!="Process")return ;//
+	            if(bIsEnc)
+	            {
+	                if(UK_Data.order<8)
+	                {
+                        SoftKey3W._SetEncBuf(UK,Inbuf[UK_Data.order],UK_Data.order);
+	                  return;
+	                }
+	               else{
+	                  order=UK_Data.order-8;
+	               }
+    	            
+	                switch(order) 
+	                {
+	                    case 0:
+	                        {
+	                           SoftKey3W.LastError=UK_Data.LastError;
+	                           if( SoftKey3W.LastError!=0){UK.close(); resolve(outb);return ;} 
+	                           Fun(UK, KeyPath); 
+	                        }
+	                        break; //
+	                    case 1:
+	                        {
+	                            SoftKey3W.LastError=UK_Data.LastError;
+	                            return_value=UK_Data.return_value;
+	                            if( SoftKey3W.LastError!=0){UK.close(); resolve(outb);return ;} 
+	                             bIsEnc=false;i=0;
+	                             SoftKey3W.ResetOrder(UK);
+						         
+	                        }
+	                        break;
+                    }
+                }
+                else{
+                      SoftKey3W.LastError=UK_Data.LastError;
+                     if( SoftKey3W.LastError!=0){
+                       UK.close();
+			           resolve(outb);return ;
+                     } 
+                    if(UK_Data.order<8)
+	                {
+	                  if(UK_Data.order>0)
+	                  {
+	                    outb[i-1]=UK_Data.return_value;
+	                  }
+	                  SoftKey3W._GetEncBuf(UK,i);//
+	                   i++;
+	                }
+	                else{
+	                 outb[i-1]=UK_Data.return_value;
+	                 UK.close();
+					  resolve(outb);return ;
+	                }
+                }
+	        } 
+	        UK.onclose = function(){
+
+	        }
+            UK.onerror = (event) => {
+                alert('未能连接服务程序,请确定服务程序是否安装。');
+            };
+	      }
+	     catch(e)  
+	      {  
+				    alert(e.name + ": " + e.message);
+				     resolve(false);
+	      }  
+	    }) 
+}
+   
+
+}
+

--
Gitblit v1.9.2