软件加密
parent
b2576e5c06
commit
763a4832b4
|
@ -0,0 +1,3 @@
|
||||||
|
// 加密关键字
|
||||||
|
const keyword = 'GNSS'
|
||||||
|
export { keyword }
|
|
@ -1,7 +1,71 @@
|
||||||
import { ipcMain, app, screen, globalShortcut, BrowserWindow } from 'electron'
|
import { ipcMain, app, screen, globalShortcut, BrowserWindow, dialog } from 'electron'
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
import './load-serialport'
|
import './load-serialport'
|
||||||
|
import { keyword } from './KeyWord'
|
||||||
|
|
||||||
|
const child_process = require('child_process')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
|
||||||
|
function queryPass(passPath: string, passValue: string) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
try {
|
||||||
|
child_process.exec(`reg query ${passPath} /v ${passValue}`, (error: Error, stdout: string, stderr: string) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve({stdout, stderr})
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function queryKey(keyPath: string, keyValue: string) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
try {
|
||||||
|
child_process.exec(`reg query ${keyPath} /v ${keyValue}`, (error: Error, stdout: string, stderr: string) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve({stdout, stderr})
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function cryptMD5(GUID: string) {
|
||||||
|
let md5 = crypto.createHash('md5')
|
||||||
|
let ciphertext = md5.update(GUID).digest('hex')
|
||||||
|
return ciphertext.slice(0,8)+'-'+ciphertext.slice(8,12)+'-'+ciphertext.slice(12,16)+'-'+ciphertext.slice(16,20)+'-'+ciphertext.slice(20,32)
|
||||||
|
}
|
||||||
|
|
||||||
|
const passPath = 'HKEY_CURRENT_USER\\SOFTWARE\\HwaSmart'
|
||||||
|
const passValue = 'BDAuthorization'
|
||||||
|
const keyPath = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography'
|
||||||
|
const keyValue = 'MachineGuid'
|
||||||
|
|
||||||
|
async function checkLaunchEnv() {
|
||||||
|
try {
|
||||||
|
const passResult: any = await queryPass(passPath, passValue)
|
||||||
|
const keyResult: any = await queryKey(keyPath, keyValue)
|
||||||
|
if(cryptMD5(keyResult.stdout.slice(83,119) + keyword) == passResult.stdout.slice(72,108)){
|
||||||
|
return true
|
||||||
|
}else{
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// 成功
|
||||||
|
// 查询到 有这个app启动项
|
||||||
|
} catch (error) {
|
||||||
|
// 没有查询到该app启动项目
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createWindow(page: string, display: any) {
|
function createWindow(page: string, display: any) {
|
||||||
const win = new BrowserWindow({
|
const win = new BrowserWindow({
|
||||||
|
@ -64,7 +128,21 @@ async function launch() {
|
||||||
globalShortcut.register('F11', () => { return })
|
globalShortcut.register('F11', () => { return })
|
||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(launch)
|
async function main() {
|
||||||
|
// 异步代码
|
||||||
|
const checkReault: any = await checkLaunchEnv()
|
||||||
|
console.log('env right:', checkReault)
|
||||||
|
|
||||||
|
// 异步代码执行完毕后执行的代码
|
||||||
|
if (checkReault) {
|
||||||
|
launch()
|
||||||
|
} else {
|
||||||
|
dialog.showErrorBox('系统提示', '软件启动出错,请联系售后技术支持人员')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.whenReady().then(main)
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
|
|
Loading…
Reference in New Issue