@@ -12,32 +12,21 @@ export default function DecryptPage() {
12
12
const [ file , setFile ] = useState ( null ) ;
13
13
const [ method , setMethod ] = useState ( "aes" ) ;
14
14
const [ key , setKey ] = useState ( "" ) ;
15
- const [ privateKey , setPrivateKey ] = useState ( "" ) ;
16
15
const [ decryptedFileUrl , setDecryptedFileUrl ] = useState ( null ) ;
17
16
const [ decryptedFileName , setDecryptedFileName ] = useState ( "" ) ;
18
17
const [ loading , setLoading ] = useState ( false ) ;
19
18
20
19
const handleDecrypt = async ( ) => {
21
- if ( ! file ) {
22
- alert ( "Please select a file to decrypt." ) ;
23
- return ;
24
- }
25
-
26
- if ( method === "rsa" && ! privateKey ) {
27
- alert ( "Please enter a private key for RSA decryption." ) ;
28
- return ;
29
- }
30
-
31
- if ( method !== "rsa" && ! key ) {
32
- alert ( "Please enter a decryption key." ) ;
20
+ if ( ! file || ( ! key && method !== "rsa" ) ) {
21
+ alert ( "Please select a file and enter a key (except RSA)." ) ;
33
22
return ;
34
23
}
35
24
36
25
setLoading ( true ) ;
37
26
const formData = new FormData ( ) ;
38
27
formData . append ( "file" , file ) ;
39
28
formData . append ( "method" , method ) ;
40
- formData . append ( "key" , method === "rsa" ? privateKey : key ) ;
29
+ formData . append ( "key" , key ) ;
41
30
42
31
try {
43
32
const response = await fetch ( `${ process . env . NEXT_PUBLIC_API_URL } /decrypt` , {
@@ -104,22 +93,7 @@ export default function DecryptPage() {
104
93
< option value = "rsa" > RSA</ option >
105
94
</ select >
106
95
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
- Private Key
113
- </ div >
114
- </ label >
115
- < textarea
116
- placeholder = "Paste RSA private key here"
117
- value = { privateKey }
118
- onChange = { ( e ) => setPrivateKey ( 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
- ) : (
96
+ { method !== "rsa" && (
123
97
< >
124
98
< label className = "block text-sm font-semibold mb-2 text-gray-300" >
125
99
< div className = "flex items-center" >
@@ -140,7 +114,7 @@ export default function DecryptPage() {
140
114
< button
141
115
onClick = { handleDecrypt }
142
116
disabled = { loading }
143
- className = "w-full bg-blue-600 hover:bg-blue-700 text-white py-3 rounded-lg font-semibold transition flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed "
117
+ className = "w-full bg-blue-600 hover:bg-blue-700 text-white py-3 rounded-lg font-semibold transition flex items-center justify-center"
144
118
>
145
119
< FaLockOpen className = "w-4 h-4 mr-2" />
146
120
{ loading ? "Decrypting..." : "Decrypt" }
0 commit comments