How do I encrypt a bash script file as aes 256 base64 and convert it to a linux executable?
I encrypted it as aes 256 base64 but I can't run it
You can't encrypt your source code and run it. You can use obfuscation techniques to make the code harder to read. Or if you want the executable to be (kind of) secure against side channels, you can use white-box cryptography techniques.
A way to do it is to build a self-extracting application, like AppImage format, or a simple self-extracting script.
Basically, a self-extracting application is composed of a specific executable (ELF binary or bash script or whatever) in charge of unpacking an archive file embedded in the executable file and execute the unpacked application. In your case, a decryption step must be added.
You can't encrypt whole script there have to be a part to decrypt it. Create a script like this:
$ cat enc
#!/bin/bash
sed '1,/encrypted part/d;1,/encrypted part/d' $0 | base64 -d > test2
chmod +x test2
./test2
exit
#-------------{ encrypted part }---------------
And the one that will be encrypted like this:
$ cat test
#!/bin/bash
echo ok
$ base64 test >> enc
The result:
$ cat enc
#!/bin/bash
sed '1,/encrypted part/d;1,/encrypted part/d' $0 | base64 -d > test2
chmod +x test2
./test2
exit
#-------------{ encrypted part }---------------
IyEvYmluL2Jhc2gKZWNobyBvawo=
Now try it:
$ ./enc
ok