diff --git a/src/components/DevAreaTools/Base64Tool.jsx b/src/components/DevAreaTools/Base64Tool.jsx new file mode 100644 index 0000000..2074d49 --- /dev/null +++ b/src/components/DevAreaTools/Base64Tool.jsx @@ -0,0 +1,94 @@ +import React, { useState } from "react"; + +export default function Base64Tool() { + const [input, setInput] = useState(""); + const [output, setOutput] = useState(""); + const [error, setError] = useState(null); + + const handleEncode = () => { + setError(null); + try { + const encoded = btoa(unescape(encodeURIComponent(input))); + setOutput(encoded); + } catch (err) { + setError("Failed to encode text."); + } + }; + + const handleDecode = () => { + setError(null); + try { + const decoded = decodeURIComponent(escape(atob(input))); + setOutput(decoded); + } catch (err) { + setError("Invalid Base64 string."); + } + }; + + const handleClear = () => { + setInput(""); + setOutput(""); + setError(null); + }; + + return ( +
+

Base64 Encoder / Decoder

+

+ Encode or decode Base64 text directly in your browser. +

+ +