This commit is contained in:
陆柯 2022-08-19 21:00:19 +08:00
commit 4911c061fe
11 changed files with 468 additions and 0 deletions

11
.hbuilderx/launch.json Normal file
View File

@ -0,0 +1,11 @@
{ // launch.json configurations app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
// launchtypelocalremote, localremote
"version": "0.0",
"configurations": [{
"type": "uniCloud",
"default": {
"launchtype": "local"
}
}
]
}

17
App.vue Normal file
View File

@ -0,0 +1,17 @@
<script>
export default {
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style>
/*每个页面公共css */
</style>

BIN
debug.xlsx Normal file

Binary file not shown.

11
main.js Normal file
View File

@ -0,0 +1,11 @@
import Vue from 'vue'
import App from './App'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()

75
manifest.json Normal file
View File

@ -0,0 +1,75 @@
{
"name" : "unicrypto",
"appid" : "__UNI__F4C3BA7",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/* 5+App */
"app-plus" : {
"usingComponents" : true,
"nvueCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/* */
"modules" : {},
/* */
"distribute" : {
/* android */
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/* ios */
"ios" : {},
/* SDK */
"sdkConfigs" : {}
}
},
/* */
"quickapp" : {},
/* */
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
},
"usingComponents" : true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
}
}

16
package.json Normal file
View File

@ -0,0 +1,16 @@
{
"dependencies": {
"bip39": "^3.0.2",
"eccrypto": "^1.1.6",
"eccrypto-js": "^5.4.0",
"hdkey": "^1.1.1",
"js-crypto-key-utils": "^0.7.3",
"secure-random": "^1.1.2",
"tic-crypto": "git+https://git.faronear.org/npm/tic-crypto"
},
"devDependencies": {
"basend-deployer": "git+https://git.faronear.org/npm/basend-deployer",
"basend-webserver": "git+https://git.faronear.org/npm/basend-webserver",
"standardx": "^6.0.0"
}
}

16
pages.json Normal file
View File

@ -0,0 +1,16 @@
{
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
}
}

246
pages/index/index.vue Normal file
View File

@ -0,0 +1,246 @@
<template>
<view class="content">
<button @click="randomBytes" style="background:#Fc4e2b">crypto.randomBytes (微信小程序失败)</button>
<button @click="scrypt" style="background:#Fc4e2b">crypto.scryptSync (全部失败)</button>
<!-- <button @click="secureRandom">secure-random库生成随机字节</button> -->
<button @click="generateMnemonic" style="background:#Fc4e2b">bip39 生成助记词 (微信小程序失败)</button>
<!-- <button @click="test4">bitcore-mnemonic库生成助记词</button>
-->
<button @click="mnemonic2seed" style="background:#Fc4e2b">bip39 从助记词到种子(安卓失败)</button>
<button @click="validateMnemonic" style="background:#Fc4e2b">bip39 验证助记词安卓失败</button>
<button @click="prikey2pubkey" style="background:#Fc4e2b">crypto 私钥转公钥安卓ios微信失败</button>
<view style="display:flex; flex-flow:row; width:100%;">
<button @click="encrypt">crypto对称加密</button>
<button @click="decrypt">crypto对称解密</button>
</view>
<view style="display:flex; flex-flow:row; width:100%;">
<button @click="sign">crypto不对称签名</button>
<button @click="verify">crypto不对称验签</button>
</view>
<view style="display:flex; flex-flow:row; width:100%;">
<button @click="encryptECC">ECC不对称加密</button>
<button @click="decryptECC">ECC不对称解密</button>
</view>
<view style="display:flex; flex-flow:row; width:100%;">
<button @click="signECC">ECC不对称签名</button>
<button @click="verifyECC">ECC不对称验签</button>
</view>
<view class="text-area">
<text class="title">{{ JSON.stringify(title) }}</text>
</view>
</view>
</template>
<script>
import crypto from 'crypto';
import ticc from 'tic-crypto';
import secureRandom from 'secure-random';
import secp256k1 from 'secp256k1';
import hdkey from 'hdkey';
import * as bip39 from 'bip39';
//import * as eccrypto from 'eccrypto-js'; // /
import eccrypto from 'eccrypto'; // /encrypt/decrypt
import keyman from 'js-crypto-key-utils';
const keypair = { prikey: '872d58c1f872636cf2ca460e85f27eb98f4a1fd5f5b70ea702a52c9bf28252ae', pubkey: '03883e6c412431729c78236f7fd6e663c92a863414d7047535b3b386a6410bf331' };
const mnemonic = '滴 民 延 腹 召 罩 巧 舟 小 顶 辩 资';
const signature = '304502210088251984a09c72a887dd8337baee3f65b580ee4e78439fc88935775719cefc670220547dc87e5288edb27990b17f535f10642704e596ce0e50f0a2252cf58dfee275';
const algorithm = 'aes-192-cbc'; // cipher key cipher aes-192 key 192/8=24 = 48 hex
const key = Buffer.from('8c0ca36264f29389e87d983b269709a92c3455178b271ae0', 'hex')
let cipherECC = {}
let signature2 = ''
export default {
data() {
return {
title: 'uni-app 加密工具兼容性测试。红色按钮的还有问题'hex_to_buf
};
},
onLoad() { },
methods: {
randomBytes() {
try {
this.title = crypto.randomBytes(16).toString('hex');
} catch (exception) {
this.title = exception.toString();
}
},
scrypt() {
try {
this.title = crypto.scryptSync('用户定义的密码', '盐值', 24);
} catch (exception) {
this.title = exception.toString();
}
},
secureRandom() {
try {
this.title = secureRandom(16).toString();
} catch (exception) {
this.title = exception.toString();
}
},
generateMnemonic() {
try {
this.title = bip39.generateMnemonic();
} catch (exception) {
this.title = exception.toString();
}
},
mnemonic2seed() {
try {
bip39.setDefaultWordlist('chinese_simplified');
this.title = bip39.mnemonicToSeedSync('滴 民 延 腹 召 罩 巧 舟 小 顶 辩 资').toString('hex'); // iosiOS appapp
} catch (exception) {
this.title = exception.toString();
}
},
prikey2pubkey() {
try {
this.title = new crypto.createECDH('secp256k1').setPrivateKey(keypair.prikey, 'hex').getPublicKey('hex', 'compressed'); // ios app setPrivateKey() : TypeError: null is not an object (evaluating 'this.rand.getBytes')
// this.title = secp256k1.publicKeyCreate(Buffer.from(keypair.prikey, 'hex'), true) //
} catch (exception) {
this.title = exception.toString();
}
},
validateMnemonic() {
// iOS app app
try {
bip39.setDefaultWordlist('chinese_simplified');
this.title = '正确结果是 true实际结果是' + bip39.validateMnemonic('滴 民 延 腹 召 罩 巧 舟 小 顶 辩 资');
} catch (exception) {
this.title = exception.toString();
}
},
encrypt() {
try {
const iv = Buffer.alloc(16, 0); //
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update('月落乌啼霜满天', 'utf8', 'hex');
encrypted += cipher.final('hex');
this.title = encrypted;
} catch (exception) {
this.title = exception.toString();
}
},
decrypt() {
try {
const iv = Buffer.alloc(16, 0); //
const decipher = crypto.createDecipheriv(algorithm, key, iv);
// 使 iv
const encrypted = "9ac679a1e7d9704df26e345fa91a8dc6feb3faa44fbf1821262a7d5910b76464";
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
this.title = decrypted;
} catch (exception) {
this.title = exception.toString();
}
},
async sign() {
try {
this.title = await ticc.sign({ data: '月落乌啼霜满天', prikey: keypair.prikey })
signature2 = this.title
} catch (exception) {
this.title = exception.toString();
}
},
async verify() {
try {
this.title = await ticc.verify({ data: '月落乌啼霜满天', signature: signature2.toUpperCase(), pubkey: keypair.pubkey }) //
} catch (exception) {
this.title = exception.toString();
}
},
typedArray2Buffer(array) {
return array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
},
async encryptECC() {
try {
// let kp=eccrypto.generateKeyPair();
var privateKey = eccrypto.generatePrivate();
var publicKey = eccrypto.getPublic(privateKey);
let kp = { privateKey, publicKey }
console.log(kp)
let encrypted = await eccrypto.encrypt(Buffer.from(ticc.hex_to_buf(keypair.pubkey)), '月落乌啼霜满天')
cipherECC = encrypted
this.title = encrypted;
} catch (exception) {
this.title = exception.toString();
}
},
async decryptECC() {
try {
let plaindata = await eccrypto.decrypt(Buffer.from(keypair.prikey, 'hex'), cipherECC)
this.title = plaindata.toString()
} catch (exception) {
this.title = exception.toString();
}
},
async signECC() {
try {
let hashBuf = crypto
.createHash('sha256')
.update('月落乌啼霜满天')
.digest();
this.title = (await eccrypto.sign(Buffer.from(keypair.prikey, 'hex'), hashBuf)).toString('hex');
} catch (exception) {
this.title = exception.toString();
}
},
async verifyECC() {
try {
let hashBuf = crypto
.createHash('sha256')
.update('月落乌啼霜满天')
.digest();
if (null === (await eccrypto.verify(Buffer.from(keypair.pubkey, 'hex'), hashBuf, Buffer.from(signature, 'hex')))) {
this.title = true;
}
} catch (exception) {
this.title = exception.toString();
}
}
}
};
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
flex-flow: column;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
word-break: break-all;
}
button {
margin: 10rpx auto;
}
</style>

BIN
static/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

76
uni.scss Normal file
View File

@ -0,0 +1,76 @@
/**
* 这里是uni-app内置的常用样式变量
*
* uni-app 官方扩展插件及插件市场https://ext.dcloud.net.cn上很多三方插件均使用了这些样式变量
* 如果你是插件开发者建议你使用scss预处理并在插件代码中直接使用这些变量无需 import 这个文件方便用户通过搭积木的方式开发整体风格一致的App
*
*/
/**
* 如果你是App开发者插件使用者你可以通过修改这些变量来定制自己的插件主题实现自定义主题功能
*
* 如果你的项目同样使用了scss预处理你也可以直接在你的 scss 代码中使用如下变量同时无需 import 这个文件
*/
/* 颜色变量 */
/* 行为相关颜色 */
$uni-color-primary: #007aff;
$uni-color-success: #4cd964;
$uni-color-warning: #f0ad4e;
$uni-color-error: #dd524d;
/* 文字基本颜色 */
$uni-text-color:#333;//基本色
$uni-text-color-inverse:#fff;//反色
$uni-text-color-grey:#999;//辅助灰色如加载更多的提示信息
$uni-text-color-placeholder: #808080;
$uni-text-color-disable:#c0c0c0;
/* 背景颜色 */
$uni-bg-color:#ffffff;
$uni-bg-color-grey:#f8f8f8;
$uni-bg-color-hover:#f1f1f1;//点击状态颜色
$uni-bg-color-mask:rgba(0, 0, 0, 0.4);//遮罩颜色
/* 边框颜色 */
$uni-border-color:#c8c7cc;
/* 尺寸变量 */
/* 文字尺寸 */
$uni-font-size-sm:24upx;
$uni-font-size-base:28upx;
$uni-font-size-lg:32upx;
/* 图片尺寸 */
$uni-img-size-sm:40upx;
$uni-img-size-base:52upx;
$uni-img-size-lg:80upx;
/* Border Radius */
$uni-border-radius-sm: 4upx;
$uni-border-radius-base: 6upx;
$uni-border-radius-lg: 12upx;
$uni-border-radius-circle: 50%;
/* 水平间距 */
$uni-spacing-row-sm: 10px;
$uni-spacing-row-base: 20upx;
$uni-spacing-row-lg: 30upx;
/* 垂直间距 */
$uni-spacing-col-sm: 8upx;
$uni-spacing-col-base: 16upx;
$uni-spacing-col-lg: 24upx;
/* 透明度 */
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
/* 文章场景相关 */
$uni-color-title: #2C405A; // 文章标题颜色
$uni-font-size-title:40upx;
$uni-color-subtitle: #555555; // 二级标题颜色
$uni-font-size-subtitle:36upx;
$uni-color-paragraph: #3F536E; // 文章段落颜色
$uni-font-size-paragraph:30upx;

BIN
unicrypto.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 KiB