Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
M
miniProgramsFormRender
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王正
miniProgramsFormRender
Commits
bb4ec28f
提交
bb4ec28f
authored
3月 07, 2025
作者:
李程佳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增加解密
上级
8eeddff7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
61 行增加
和
75 行删除
+61
-75
common.js
common.js
+0
-0
index.html
index.html
+31
-45
sm2.js
sm2.js
+30
-30
没有找到文件。
common.js
浏览文件 @
bb4ec28f
This source diff could not be displayed because it is too large. You can
view the blob
instead.
index.html
浏览文件 @
bb4ec28f
...
...
@@ -4,7 +4,7 @@
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Document
</title>
<title
id=
"title"
>
Document
</title>
<link
rel=
"stylesheet"
href=
"element-ui.min.css"
>
<link
rel=
"stylesheet"
href=
"VFormRender.css"
>
<style
type=
"text/css"
>
...
...
@@ -12,6 +12,17 @@
margin
:
0
;
padding
:
0
;
}
body
,
html
{
width
:
100%
;
height
:
100%
;
margin
:
0
;
font-family
:
"微软雅黑"
;
}
#container
{
width
:
100%
;
height
:
100%
;
overflow
:
hidden
;
}
</style>
</head>
...
...
@@ -20,46 +31,11 @@
<v-form-render
:preview-state=
"true"
identi-fication=
'XCX'
:form-json=
"formJson"
:form-data=
"formData"
:option-data=
"optionData"
ref=
"vFormRef"
>
</v-form-render>
<!-- <el-button type="primary">Button</el-button> -->
<!-- <div>{{msg}}</div>
<button @click="btnClick">我是按钮</button> -->
</div>
<!-- <div id="testStr">
</div> -->
<!-- <script type="text/javascript">
var userAgent = navigator.userAgent;
if (userAgent.indexOf('AlipayClient') > -1) {
// 支付宝小程序的 JS-SDK 防止 404 需要动态加载,如果不需要兼容支付宝小程序,则无需引用此 JS 文件。
document.writeln('<script src="https://appx/web-view.min.js"' + '>' + '<' + '/' + 'script>');
} else if (/QQ/i.test(userAgent) && /miniProgram/i.test(userAgent)) {
// QQ 小程序
document.write(
'<script type="text/javascript" src="https://qqq.gtimg.cn/miniprogram/webview_jssdk/qqjssdk-1.0.0.js"><\/script>'
);
} else if (/miniProgram/i.test(userAgent) && /micromessenger/i.test(userAgent)) {
// 微信小程序 JS-SDK 如果不需要兼容微信小程序,则无需引用此 JS 文件。
document.write('<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"><\/script>');
} else if (/toutiaomicroapp/i.test(userAgent)) {
// 头条小程序 JS-SDK 如果不需要兼容头条小程序,则无需引用此 JS 文件。
document.write(
'<script type="text/javascript" src="https://s3.pstatp.com/toutiao/tmajssdk/jssdk-1.0.1.js"><\/script>');
} else if (/swan/i.test(userAgent)) {
// 百度小程序 JS-SDK 如果不需要兼容百度小程序,则无需引用此 JS 文件。
document.write(
'<script type="text/javascript" src="https://b.bdstatic.com/searchbox/icms/searchbox/js/swan-2.0.18.js"><\/script>'
);
} else if (/quickapp/i.test(userAgent)) {
// quickapp
document.write('<script type="text/javascript" src="https://quickapp/jssdk.webview.min.js"><\/script>');
}
</script> -->
<script
src=
"jsbn.js"
></script>
<script
src=
"sm2.js"
></script>
<script
src=
"vuex.min.js"
></script>
<script
src=
"vue.min.js"
></script>
<script
src=
"vuex.min.js"
></script>
<script
src=
"mitt.js"
></script>
<script
src=
"element-ui.min.js"
></script>
<script
src=
"VFormRender.umd.js"
></script>
...
...
@@ -67,8 +43,8 @@
<script
src=
"common.js"
></script>
<script
src=
"uni-webview.js"
></script>
<script
src=
"jweixin.js"
></script>
<script
type=
"text/javascript"
src=
"//api.map.baidu.com/api?type=webgl&v=1.0&ak=Qs1baeL6A2D4ws0DAVKpWGw5ILNRbyvb"
></script>
<script>
// alert("加载页面")
console
.
log
(
"开始获取浏览器参数==>"
)
let
keypair
=
sm2
.
generateKeyPairHex
()
let
publicKey
=
keypair
.
publicKey
...
...
@@ -78,19 +54,21 @@
var
vm
let
params
=
getUrlPatams
()
let
urlParams
=
JSON
.
parse
(
params
)
console
.
log
(
'-----------urlParams--'
,
urlParams
)
document
.
getElementById
(
'title'
).
innerHTML
=
urlParams
.
title
if
(
urlParams
.
sessionData
){
setSessionStorage
(
urlParams
.
sessionData
)
}
// 存放参数
setLocalData
(
urlParams
)
// 初始化请求头
let
headers
=
initRequestHead
()
console
.
log
(
"请求头"
,
headers
);
// 初始化请求类
let
request
=
initRequest
(
headers
,
urlParams
.
modeEvn
)
let
request
=
initRequest
(
headers
,
urlParams
.
modeEvn
,
urlParams
.
SERVER_PUBLIC_KEY
,
urlParams
.
PRIVATE_KEY
)
// let request = initRequest(headers)
var
__glob_easyform_html_obj
=
{
async
customMethods
(
requestConfig
)
{
console
.
log
(
'requestConfig'
,
requestConfig
);
let
{
requestMethod
,
url
,
headers
,
data
,
params
}
=
requestConfig
return
await
request
({
url
,
...
...
@@ -105,6 +83,7 @@
})
}
}
window
.
onload
=
async
function
()
{
console
.
log
(
"HTML加载完毕==>"
)
vm
=
new
Vue
({
...
...
@@ -123,6 +102,11 @@
// 获取funcNo
let
res
=
await
this
.
getFuncNo
()
if
(
res
.
code
===
'000000'
)
{
sessionStorage
.
setItem
(
'tempNo'
,
res
.
retObj
.
tempNo
)
// 这里是模拟数据
// let json = await MockJson()
// 设置json串
// this.$refs.vFormRef.setFormJson(json)
// 获取json串
let
res1
=
await
this
.
getJsonCode
(
res
.
retObj
.
funcNo
)
if
(
res1
.
code
===
'000000'
)
{
...
...
@@ -131,10 +115,11 @@
}
// 这里是模拟数据
// let json = await MockJson()
// 设置json串
//
//
设置json串
// this.$refs.vFormRef.setFormJson(json)
this
.
loading
=
false
// await this.getLoanJsonCode()
// await this.getLocation()
},
methods
:
{
// 获取字典
...
...
@@ -156,12 +141,14 @@
},
//获取funcNo
async
getFuncNo
()
{
const
tempBigClass
=
urlParams
.
tempBigClass
const
tempSmallClass
=
urlParams
.
tempSmallClass
let
res
=
await
request
({
url
:
'/XCX_CDB02031101'
,
method
:
'post'
,
data
:
{
tempBigClass
:
'smes'
,
tempSmallClass
:
'smes02'
,
tempBigClass
:
tempBigClass
,
tempSmallClass
:
tempSmallClass
,
},
headers
:
{
SERVICE_ID
:
'cmdb'
,
...
...
@@ -207,7 +194,6 @@
}
})
}
</script>
</body>
...
...
sm2.js
浏览文件 @
bb4ec28f
...
...
@@ -641,7 +641,7 @@ function verifyPublicKey(publicKey) {
return
y
.
square
().
equals
(
x
.
multiply
(
x
.
square
()).
add
(
x
.
multiply
(
curve
.
a
)).
add
(
curve
.
b
))
}
var
_
=
{
var
aa
=
{
getGlobalCurve
,
generateEcparam
,
generateKeyPairHex
,
...
...
@@ -881,17 +881,17 @@ function sm3 (array) {
// SM2.js
const
{
G
,
curve
,
n
}
=
_
.
generateEcparam
()
const
{
G
,
curve
,
n
}
=
aa
.
generateEcparam
()
const
C1C2C3
=
0
/**
* 加密
*/
function
doEncrypt
(
msg
,
publicKey
,
cipherMode
=
1
)
{
msg
=
typeof
msg
===
'string'
?
_
.
hexToArray
(
_
.
utf8ToHex
(
msg
))
:
Array
.
prototype
.
slice
.
call
(
msg
)
publicKey
=
_
.
getGlobalCurve
().
decodePointHex
(
publicKey
)
// 先将公钥转成点
msg
=
typeof
msg
===
'string'
?
aa
.
hexToArray
(
aa
.
utf8ToHex
(
msg
))
:
Array
.
prototype
.
slice
.
call
(
msg
)
publicKey
=
aa
.
getGlobalCurve
().
decodePointHex
(
publicKey
)
// 先将公钥转成点
const
keypair
=
_
.
generateKeyPairHex
()
const
keypair
=
aa
.
generateKeyPairHex
()
const
k
=
new
BigInteger
(
keypair
.
privateKey
,
16
)
// 随机数 k
// c1 = k * G
...
...
@@ -900,11 +900,11 @@ function doEncrypt(msg, publicKey, cipherMode = 1) {
// (x2, y2) = k * publicKey
const
p
=
publicKey
.
multiply
(
k
)
const
x2
=
_
.
hexToArray
(
_
.
leftPad
(
p
.
getX
().
toBigInteger
().
toRadix
(
16
),
64
))
const
y2
=
_
.
hexToArray
(
_
.
leftPad
(
p
.
getY
().
toBigInteger
().
toRadix
(
16
),
64
))
const
x2
=
aa
.
hexToArray
(
aa
.
leftPad
(
p
.
getX
().
toBigInteger
().
toRadix
(
16
),
64
))
const
y2
=
aa
.
hexToArray
(
aa
.
leftPad
(
p
.
getY
().
toBigInteger
().
toRadix
(
16
),
64
))
// c3 = hash(x2 || msg || y2)
const
c3
=
_
.
arrayToHex
(
sm3
([].
concat
(
x2
,
msg
,
y2
)))
const
c3
=
aa
.
arrayToHex
(
sm3
([].
concat
(
x2
,
msg
,
y2
)))
let
ct
=
1
let
offset
=
0
...
...
@@ -926,7 +926,7 @@ function doEncrypt(msg, publicKey, cipherMode = 1) {
// c2 = msg ^ t
msg
[
i
]
^=
t
[
offset
++
]
&
0xff
}
const
c2
=
_
.
arrayToHex
(
msg
)
const
c2
=
aa
.
arrayToHex
(
msg
)
return
cipherMode
===
C1C2C3
?
c1
+
c2
+
c3
:
c1
+
c3
+
c2
}
...
...
@@ -947,12 +947,12 @@ function doDecrypt(encryptData, privateKey, cipherMode = 1, {
c2
=
encryptData
.
substr
(
128
,
encryptData
.
length
-
128
-
64
)
}
const
msg
=
_
.
hexToArray
(
c2
)
const
c1
=
_
.
getGlobalCurve
().
decodePointHex
(
'04'
+
encryptData
.
substr
(
0
,
128
))
const
msg
=
aa
.
hexToArray
(
c2
)
const
c1
=
aa
.
getGlobalCurve
().
decodePointHex
(
'04'
+
encryptData
.
substr
(
0
,
128
))
const
p
=
c1
.
multiply
(
privateKey
)
const
x2
=
_
.
hexToArray
(
_
.
leftPad
(
p
.
getX
().
toBigInteger
().
toRadix
(
16
),
64
))
const
y2
=
_
.
hexToArray
(
_
.
leftPad
(
p
.
getY
().
toBigInteger
().
toRadix
(
16
),
64
))
const
x2
=
aa
.
hexToArray
(
aa
.
leftPad
(
p
.
getX
().
toBigInteger
().
toRadix
(
16
),
64
))
const
y2
=
aa
.
hexToArray
(
aa
.
leftPad
(
p
.
getY
().
toBigInteger
().
toRadix
(
16
),
64
))
let
ct
=
1
let
offset
=
0
...
...
@@ -976,10 +976,10 @@ function doDecrypt(encryptData, privateKey, cipherMode = 1, {
}
// c3 = hash(x2 || msg || y2)
const
checkC3
=
_
.
arrayToHex
(
sm3
([].
concat
(
x2
,
msg
,
y2
)))
const
checkC3
=
aa
.
arrayToHex
(
sm3
([].
concat
(
x2
,
msg
,
y2
)))
if
(
checkC3
===
c3
)
{
return
output
===
'array'
?
msg
:
_
.
arrayToUtf8
(
msg
)
return
output
===
'array'
?
msg
:
aa
.
arrayToUtf8
(
msg
)
}
else
{
return
output
===
'array'
?
[]
:
''
}
...
...
@@ -995,7 +995,7 @@ function doSignature(msg, privateKey, {
publicKey
,
userId
}
=
{})
{
let
hashHex
=
typeof
msg
===
'string'
?
_
.
utf8ToHex
(
msg
)
:
_
.
arrayToHex
(
msg
)
let
hashHex
=
typeof
msg
===
'string'
?
aa
.
utf8ToHex
(
msg
)
:
aa
.
arrayToHex
(
msg
)
if
(
hash
)
{
// sm3杂凑
...
...
@@ -1031,7 +1031,7 @@ function doSignature(msg, privateKey, {
if
(
der
)
return
encodeDer
(
r
,
s
)
// asn.1 der 编码
return
_
.
leftPad
(
r
.
toString
(
16
),
64
)
+
_
.
leftPad
(
s
.
toString
(
16
),
64
)
return
aa
.
leftPad
(
r
.
toString
(
16
),
64
)
+
aa
.
leftPad
(
s
.
toString
(
16
),
64
)
}
/**
...
...
@@ -1042,7 +1042,7 @@ function doVerifySignature(msg, signHex, publicKey, {
hash
,
userId
}
=
{})
{
let
hashHex
=
typeof
msg
===
'string'
?
_
.
utf8ToHex
(
msg
)
:
_
.
arrayToHex
(
msg
)
let
hashHex
=
typeof
msg
===
'string'
?
aa
.
utf8ToHex
(
msg
)
:
aa
.
arrayToHex
(
msg
)
if
(
hash
)
{
// sm3杂凑
...
...
@@ -1083,15 +1083,15 @@ function doVerifySignature(msg, signHex, publicKey, {
*/
function
getHash
(
hashHex
,
publicKey
,
userId
=
'1234567812345678'
)
{
// z = hash(entl || userId || a || b || gx || gy || px || py)
userId
=
_
.
utf8ToHex
(
userId
)
const
a
=
_
.
leftPad
(
G
.
curve
.
a
.
toBigInteger
().
toRadix
(
16
),
64
)
const
b
=
_
.
leftPad
(
G
.
curve
.
b
.
toBigInteger
().
toRadix
(
16
),
64
)
const
gx
=
_
.
leftPad
(
G
.
getX
().
toBigInteger
().
toRadix
(
16
),
64
)
const
gy
=
_
.
leftPad
(
G
.
getY
().
toBigInteger
().
toRadix
(
16
),
64
)
userId
=
aa
.
utf8ToHex
(
userId
)
const
a
=
aa
.
leftPad
(
G
.
curve
.
a
.
toBigInteger
().
toRadix
(
16
),
64
)
const
b
=
aa
.
leftPad
(
G
.
curve
.
b
.
toBigInteger
().
toRadix
(
16
),
64
)
const
gx
=
aa
.
leftPad
(
G
.
getX
().
toBigInteger
().
toRadix
(
16
),
64
)
const
gy
=
aa
.
leftPad
(
G
.
getY
().
toBigInteger
().
toRadix
(
16
),
64
)
if
(
publicKey
.
length
>
128
)
publicKey
=
publicKey
.
substr
(
2
,
128
)
// 干掉 '04'
const
px
=
publicKey
.
substr
(
0
,
64
)
const
py
=
publicKey
.
substr
(
64
,
64
)
const
data
=
_
.
hexToArray
(
userId
+
a
+
b
+
gx
+
gy
+
px
+
py
)
const
data
=
aa
.
hexToArray
(
userId
+
a
+
b
+
gx
+
gy
+
px
+
py
)
const
entl
=
userId
.
length
*
4
data
.
unshift
(
entl
&
0x00ff
)
...
...
@@ -1100,7 +1100,7 @@ function getHash(hashHex, publicKey, userId = '1234567812345678') {
const
z
=
sm3
(
data
)
// e = hash(z || msg)
return
_
.
arrayToHex
(
sm3
(
z
.
concat
(
_
.
hexToArray
(
hashHex
))))
return
aa
.
arrayToHex
(
sm3
(
z
.
concat
(
aa
.
hexToArray
(
hashHex
))))
}
/**
...
...
@@ -1108,8 +1108,8 @@ function getHash(hashHex, publicKey, userId = '1234567812345678') {
*/
function
getPublicKeyFromPrivateKey
(
privateKey
)
{
const
PA
=
G
.
multiply
(
new
BigInteger
(
privateKey
,
16
))
const
x
=
_
.
leftPad
(
PA
.
getX
().
toBigInteger
().
toString
(
16
),
64
)
const
y
=
_
.
leftPad
(
PA
.
getY
().
toBigInteger
().
toString
(
16
),
64
)
const
x
=
aa
.
leftPad
(
PA
.
getX
().
toBigInteger
().
toString
(
16
),
64
)
const
y
=
aa
.
leftPad
(
PA
.
getY
().
toBigInteger
().
toString
(
16
),
64
)
return
'04'
+
x
+
y
}
...
...
@@ -1117,7 +1117,7 @@ function getPublicKeyFromPrivateKey(privateKey) {
* 获取椭圆曲线点
*/
function
getPoint
()
{
const
keypair
=
_
.
generateKeyPairHex
()
const
keypair
=
aa
.
generateKeyPairHex
()
const
PA
=
curve
.
decodePointHex
(
keypair
.
publicKey
)
keypair
.
k
=
new
BigInteger
(
keypair
.
privateKey
,
16
)
...
...
@@ -1152,8 +1152,8 @@ var sm2 = {
// 加密
const
serverEncrypt
=
(
text
)
=>
{
const
publicKey
=
uni
.
getStorageSync
(
'SERVER_PUBLIC_KEY'
)
const
serverEncrypt
=
(
text
,
publicKey
,
cipherMode
)
=>
{
//
const publicKey = uni.getStorageSync('SERVER_PUBLIC_KEY')
if
(
publicKey
)
{
const
encryptTxt
=
sm2
.
doEncrypt
(
text
,
publicKey
,
cipherMode
)
return
encryptTxt
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论