[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to encrypt/decrypt text files in Unix

Posted on 2005-05-05
Medium Priority
Last Modified: 2013-12-26
Hi Experts,

I have set of text files which needs to be encrypted and decrypted.

Pls. let me know if any unix/shell commands exists to encrypt text files.

Thanks in advance
Question by:sganta
  • 3
  • 2
  • 2
  • +2
LVL 12

Accepted Solution

stefan73 earned 256 total points
ID: 13937546
Hi sganta,
There's Unix crypt, but don't use it. It's weak encryption. If you need strong encryption, you could use PGP in symmetric mode.

Do you need to store the files crypted, or is it just for communication?


LVL 48

Assisted Solution

Tintin earned 248 total points
ID: 13941346

No point in using crypt anyway, as it is only a one way encryption method.  There's no way to decrypt a crypted text.

I'll second PGP.  Use the opensource GNUpg

See http://www.gnupg.org/

Author Comment

ID: 13942501
Hi Stefan and Tintin,

Thanks for your valuable inputs. We have software files Shell scripts. Would like to encrypt and decrypt
the shell scripts while using at Customer Site.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 48

Expert Comment

ID: 13942537
What exactly do you mean that you want to encrypt/decrypt shell scripts?  What are you trying to achieve?
LVL 16

Assisted Solution

manav_mathur earned 248 total points
ID: 13942564
You could also use the OpenSSL suite(open source).

From 'man openssl'

       The openssl program is a command line tool for using the various cryp-
       tography functions of OpenSSL's crypto library from the shell.  It can
       be used for

        o  Creation of RSA, DH and DSA key parameters
        o  Creation of X.509 certificates, CSRs and CRLs
        o  Calculation of Message Digests
        o  Encryption and Decryption with Ciphers
        o  SSL/TLS Client and Server Tests
        o  Handling of S/MIME signed or encrypted mail

LVL 51

Assisted Solution

ahoffmann earned 248 total points
ID: 13943426
> .. have software files Shell scripts. Would like to encrypt and decrypt
the shell scripts while using at Customer Site..

hmm about en-/decrypt anything has been said
If your goal is to get your scripts protected against (human) reading at customer site, then this is a useless attempt. In short words: impossible.
If your goal is to make the scripts immune to (manual) changes at customer side, short word again: impossible.
In both cases you can just obfuscate things, that's all.
LVL 12

Expert Comment

ID: 13943502
I second ahoffmann.

The problem is that you need to decode your files somewhere. This will have to happen in the scripts; any nosey Unix user will be able to do that, too.

Another problem is that scripts require read rights to be executed. Setting the 'x' bit without the 'r' bit won't work, this only works for binaries.

The only way to use encoded scripts is to embed them in a binary framework which will handle all the decryption and execute them as a call to exec(). Technically speaking, those won't be scripts anymore and you'll lose the ease in maintaining them.

You could check if the shell supports reading scripts from a FIFO; this would enable you to write the decoded script by your binary, while the shell is reading it. This won't leave decoded script snippets somewhere on the drive.
LVL 51

Expert Comment

ID: 13943881
>  This won't leave decoded script snippets somewhere on the drive.
.. but in memory ;-)
LVL 12

Expert Comment

ID: 13944405
yes, there's no 100% security - the wrapper binary would have to go a long way to keep out curious eyes...

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question