mirror of
https://github.com/zyqunix/tools.git
synced 2025-07-06 06:20:30 +02:00
add base64 encoder/decoder
This commit is contained in:
parent
825c90e3b1
commit
a0cff01c36
3 changed files with 87 additions and 0 deletions
23
base64/index.js
Normal file
23
base64/index.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
const decodeElem = document.getElementById('decodeInput');
|
||||
const encodeElem = document.getElementById('encodeInput');
|
||||
const decodeOut = document.getElementById('decodeOutput');
|
||||
const encodeOut = document.getElementById('encodeOutput');
|
||||
|
||||
function encodeBase64() {
|
||||
const input = encodeElem.value;
|
||||
const encoded = btoa(input);
|
||||
encodeOut.value = encoded;
|
||||
}
|
||||
|
||||
function decodeBase64() {
|
||||
const input = decodeElem.value;
|
||||
try {
|
||||
const decoded = atob(input);
|
||||
decodeOut.value = decoded;
|
||||
} catch {
|
||||
decodeOut.value = 'Invalid Base64 input';
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('encode').addEventListener('click', encodeBase64);
|
||||
document.getElementById('decode').addEventListener('click', decodeBase64);
|
Loading…
Add table
Add a link
Reference in a new issue