MCPcopy Create free account
hub / github.com/aghyad97/browserytools / TextEncryption

Function TextEncryption

src/components/TextEncryption.tsx:71–241  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69 return Array.from(arr, (b) => chars[b % chars.length]).join("");
70}
71export default function TextEncryption() {
72 const t = useTranslations("Tools.TextEncryption");
73 const tc = useTranslations("ToolsConfig");
74 const [inputText, setInputText] = useState("");
75 const [password, setPassword] = useState("");
76 const [outputText, setOutputText] = useState("");
77 const [showPassword, setShowPassword] = useState(false);
78 const [isProcessing, setIsProcessing] = useState(false);
79 const [error, setError] = useState<string | null>(null);
80 const doEncrypt = async () => {
81 if (!inputText.trim()) { toast.error(t("enterTextToEncrypt")); return; }
82 if (!password) { toast.error(t("enterEncryptionPassword")); return; }
83 setIsProcessing(true); setError(null);
84 try {
85 const result = await encryptText(inputText, password);
86 setOutputText(result);
87 toast.success(t("encryptedSuccess"));
88 } catch (e) {
89 const msg = (e instanceof Error ? e.message : t("encryptionFailed"));
90 setError(msg); toast.error(t("encryptionFailed"));
91 } finally { setIsProcessing(false); }
92 };
93
94 const doDecrypt = async () => {
95 if (!inputText.trim()) { toast.error(t("enterTextToDecrypt")); return; }
96 if (!password) { toast.error(t("enterDecryptionPassword")); return; }
97 setIsProcessing(true); setError(null);
98 try {
99 const result = await decryptText(inputText, password);
100 setOutputText(result);
101 toast.success(t("decryptedSuccess"));
102 } catch {
103 const msg = t("decryptionFailed");
104 setError(msg); toast.error(msg);
105 } finally { setIsProcessing(false); }
106 };
107
108 const doClear = () => { setInputText(""); setOutputText(""); setError(null); };
109 const doGenerateKey = () => {
110 setPassword(generateRandomKey(24));
111 setShowPassword(true);
112 toast.success(t("randomKeyGenerated"));
113 };
114 return (
115 <ToolShell
116 slug="text-encryption"
117 title={tc("tools.text-encryption.name")}
118 sub={tc("tools.text-encryption.description")}
119 >
120 <div className="max-w-3xl mx-auto space-y-6">
121 {/* Security note */}
122 <Alert className="border-green-200 bg-green-50 dark:bg-green-950 dark:border-green-800">
123 <Shield className="h-4 w-4 text-green-600" />
124 <AlertDescription className="text-green-700 dark:text-green-300">
125 {t("securityNote")}
126 </AlertDescription>
127 </Alert>
128 {/* Password input */}

Callers

nothing calls this directly

Calls 3

successMethod · 0.80
errorMethod · 0.80
copyToClipboardFunction · 0.70

Tested by

no test coverage detected