"use client"; import React, { useState } from "react"; import CryptoJS from "crypto-js"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Shield, Lock, Unlock, Copy } from "lucide-react"; import { toast } from "sonner"; const ALGORITHMS = [ { value: "AES", label: "AES" }, { value: "DES", label: "DES" }, { value: "TripleDES", label: "TripleDES" }, { value: "Rabbit", label: "Rabbit" }, { value: "RC4", label: "RC4" }, ]; export default function AesDesPage() { const [input, setInput] = useState(""); const [key, setKey] = useState(""); const [algorithm, setAlgorithm] = useState("AES"); const [output, setOutput] = useState(""); const handleProcess = (mode: "encrypt" | "decrypt") => { if (!input) return; if (!key) { toast.error("请输入密钥"); return; } try { let result = ""; const algo = (CryptoJS as any)[algorithm]; if (mode === "encrypt") { result = algo.encrypt(input, key).toString(); toast.success("加密成功"); } else { const bytes = algo.decrypt(input, key); result = bytes.toString(CryptoJS.enc.Utf8); if (!result) throw new Error("解密失败(可能是密钥错误)"); toast.success("解密成功"); } setOutput(result); } catch (e: any) { toast.error("处理失败: " + e.message); setOutput(""); } }; const copyToClipboard = async (text: string) => { try { await navigator.clipboard.writeText(text); toast.success("已复制到剪贴板"); } catch { toast.error("复制失败"); } }; return (
支持 AES, DES, RC4 等常用对称加密算法
安全性提示:所有计算均在本地浏览器执行,密钥不会发送到服务器。