88 lines
2.4 KiB
PHP
88 lines
2.4 KiB
PHP
<?php
|
|
/*
|
|
* 已知问题:
|
|
* 不支持ascii码以外字符
|
|
* key长度超过data长度时,结果时data长度下key的计算结果
|
|
* 所以还是用现成的比较好的加密算法为好
|
|
*/
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>加密解密</title>
|
|
</head>
|
|
<body>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
<label for="raw_text1">明文:</label>
|
|
</td>
|
|
<td>
|
|
<textarea name="raw_text" id="raw_text1"></textarea>
|
|
</td>
|
|
<td>
|
|
<button name="ev_bt" id="ev_bt1" onclick="req_enc()">加密↓</button>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="key1">密钥:</label>
|
|
</td>
|
|
<td>
|
|
<textarea name="key" id="key1" required></textarea>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="enc_text1">密文:</label>
|
|
</td>
|
|
<td>
|
|
<textarea name="enc_text" id="enc_text1"></textarea>
|
|
</td>
|
|
<td>
|
|
<button name="ev_bt" id="ev_bt2" onclick="req_dec()">解密↑</button>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<script>
|
|
function req_enc() {
|
|
const rawText = document.getElementById("raw_text1").value;
|
|
const key = document.getElementById('key1').value;
|
|
const data = {raw_text: rawText, key: key};
|
|
|
|
fetch('15.work2.api.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data),
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById("enc_text1").value = data;
|
|
})
|
|
.catch(error => console.error('Error:', error));
|
|
}
|
|
|
|
function req_dec() {
|
|
const encText = document.getElementById("enc_text1").value;
|
|
const key = document.getElementById('key1').value;
|
|
const data = {enc_text: encText, key: key};
|
|
|
|
fetch('15.work2.api.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data),
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById("raw_text1").value = data;
|
|
})
|
|
.catch(error => console.error('Error:', error));
|
|
}
|
|
|
|
</script>
|
|
</body>
|