argon2Test

This commit is contained in:
chenqiang 2025-08-25 23:42:31 +08:00
commit 357cdf0684
7 changed files with 1290 additions and 0 deletions

39
.gitignore vendored Normal file
View File

@ -0,0 +1,39 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# Build files
build/
.cache/
# OS generated files
Thumbs.db
.DS_Store

1
.python-version Normal file
View File

@ -0,0 +1 @@
2.7.18

46
background/main.js Normal file
View File

@ -0,0 +1,46 @@
const { app, BrowserWindow, ipcMain } = require('electron')
const { argon2Test } = require('./service/argon2.js')
function createWindow () {
// 创建浏览器窗口
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
})
// 加载index.html文件
win.loadFile('index.html')
// 打开开发者工具
// win.webContents.openDevTools()
}
// 注册IPC接口处理程序
ipcMain.handle('argon2-test', async (event, inputString) => {
// 调用argon2Test方法处理输入字符串
return await argon2Test(inputString);
});
// 当Electron完成初始化并准备创建浏览器窗口时调用此方法
app.whenReady().then(() => {
createWindow()
// macOS中点击Dock图标并且没有其他窗口打开时重新创建一个窗口
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
// 当所有窗口关闭时退出应用
app.on('window-all-closed', () => {
// 在macOS上除非用户用Cmd + Q确定退出否则绝大部分应用及其菜单栏会保持激活
if (process.platform !== 'darwin') {
app.quit()
}
})

View File

@ -0,0 +1,23 @@
const argon2 = require('argon2');
// argon2Test方法接收一个字符串返回其argon2哈希值
async function argon2Test(inputString) {
try {
// 使用默认配置生成argon2哈希
const hash = await argon2.hash(inputString);
return {
success: true,
hash: hash
};
} catch (error) {
console.error('argon2哈希计算失败:', error);
return {
success: false,
error: error.message
};
}
}
module.exports = {
argon2Test
};

119
index.html Normal file
View File

@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello Electron!</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
margin: 0;
padding: 20px;
text-align: center;
}
h1 {
color: #333;
}
.argon2-form {
margin: 20px auto;
max-width: 500px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
}
input[type="text"] {
padding: 10px;
width: 70%;
margin-right: 10px;
border: 1px solid #ddd;
border-radius: 3px;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
padding: 10px;
border-radius: 3px;
text-align: left;
word-break: break-all;
}
.success {
background-color: #dff0d8;
border: 1px solid #d6e9c6;
color: #3c763d;
}
.error {
background-color: #f2dede;
border: 1px solid #ebccd1;
color: #a94442;
}
</style>
</head>
<body>
<h1>Hello Electron 11!</h1>
<p>这是一个使用Node.js 12和Electron 11初始化的项目。</p>
<div>
<p>当前Node.js版本: <script>document.write(process.version)</script></p>
<p>当前Electron版本: <script>document.write(process.versions.electron)</script></p>
</div>
<!-- Argon2哈希测试表单 -->
<div class="argon2-form">
<h2>Argon2哈希测试</h2>
<input type="text" id="inputText" placeholder="输入要哈希的文本" />
<button id="hashButton">生成哈希</button>
<div id="result" class="result"></div>
</div>
<script>
const { ipcRenderer } = require('electron');
document.getElementById('hashButton').addEventListener('click', async () => {
const inputText = document.getElementById('inputText').value;
const resultElement = document.getElementById('result');
if (!inputText) {
resultElement.innerHTML = '请输入文本';
resultElement.className = 'result error';
return;
}
// 显示加载状态
resultElement.innerHTML = '正在生成哈希...';
resultElement.className = 'result';
try {
// 调用主进程的argon2-test接口
const result = await ipcRenderer.invoke('argon2-test', inputText);
if (result.success) {
resultElement.innerHTML = `成功生成哈希:<br>${result.hash}`;
resultElement.className = 'result success';
} else {
resultElement.innerHTML = `生成哈希失败:<br>${result.error}`;
resultElement.className = 'result error';
}
} catch (error) {
resultElement.innerHTML = `发生错误:<br>${error.message}`;
resultElement.className = 'result error';
}
});
// 允许按Enter键提交表单
document.getElementById('inputText').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
document.getElementById('hashButton').click();
}
});
</script>
</body>
</html>

1046
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

16
package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "electron11",
"version": "1.0.0",
"main": "background/main.js",
"scripts": {
"start": "electron ."
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"argon2": "^0.28.5",
"electron": "^11.5.0"
}
}