Skip to content

Commit f49913f

Browse files
committed
Update rsa encryption with size warning
1 parent 0835bf6 commit f49913f

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/app/decrypt/page.jsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,25 @@ export default function DecryptPage() {
9090
>
9191
<option value="aes">AES</option>
9292
<option value="3des">3DES</option>
93-
<option value="rsa">RSA</option>
93+
<option value="rsa">RSA (max file size: 190 bytes)</option>
9494
</select>
9595

96-
{method !== "rsa" && (
96+
{method === "rsa" ? (
97+
<>
98+
<label className="block text-sm font-semibold mb-2 text-gray-300">
99+
<div className="flex items-center">
100+
<FaKey className="w-4 h-4 mr-2" />
101+
Private Key
102+
</div>
103+
</label>
104+
<textarea
105+
placeholder="Paste RSA private key here"
106+
value={key}
107+
onChange={(e) => setKey(e.target.value)}
108+
className="mb-6 w-full p-2 border border-gray-600 rounded-md bg-gray-900 text-sm text-white h-32 font-mono"
109+
/>
110+
</>
111+
) : (
97112
<>
98113
<label className="block text-sm font-semibold mb-2 text-gray-300">
99114
<div className="flex items-center">

src/app/encrypt/page.jsx

+25-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ export default function EncryptPage() {
1616
const [encryptedFileName, setEncryptedFileName] = useState("");
1717
const [loading, setLoading] = useState(false);
1818

19+
const RSA_MAX_SIZE = 190; // Maximum size in bytes for RSA-2048 with OAEP padding
20+
1921
const handleEncrypt = async () => {
2022
if (!file || (!key && method !== "rsa")) {
2123
alert("Please select a file and enter a key (except RSA).");
2224
return;
2325
}
2426

27+
// Check file size for RSA
28+
if (method === "rsa" && file.size > RSA_MAX_SIZE) {
29+
alert(`RSA encryption is limited to files smaller than ${RSA_MAX_SIZE} bytes. Your file is ${file.size} bytes. Please use AES or 3DES for larger files.`);
30+
return;
31+
}
32+
2533
setLoading(true);
2634
const formData = new FormData();
2735
formData.append("file", file);
@@ -92,11 +100,26 @@ export default function EncryptPage() {
92100
>
93101
<option value="aes">AES</option>
94102
<option value="3des">3DES</option>
95-
<option value="rsa">RSA</option>
103+
<option value="rsa">RSA (max file size: 190 bytes)</option>
96104
</select>
97105

98106
{/* Key input */}
99-
{method !== "rsa" && (
107+
{method === "rsa" ? (
108+
<>
109+
<label className="block text-sm font-semibold mb-2 text-gray-300">
110+
<div className="flex items-center">
111+
<FaKey className="w-4 h-4 mr-2" />
112+
Public Key
113+
</div>
114+
</label>
115+
<textarea
116+
placeholder="Paste RSA public key here"
117+
value={key}
118+
onChange={(e) => setKey(e.target.value)}
119+
className="mb-6 w-full p-2 border border-gray-600 rounded-md bg-gray-900 text-sm text-white h-32 font-mono"
120+
/>
121+
</>
122+
) : (
100123
<>
101124
<label className="block text-sm font-semibold mb-2 text-gray-300">
102125
<div className="flex items-center">

0 commit comments

Comments
 (0)