[ Table Of Contents ][ Answer Guy Current Index ] greetings   1   2   3   4   5   6   7   8 [ Index of Past Answers ]


(?) The Answer Gang (!)


By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and the Gang, the Editors of Linux Gazette... and You!
Send questions (or interesting answers) to linux-questions-only@ssc.com

There is no guarantee that your questions here will ever be answered. Readers at confidential sites must provide permission to publish. However, you can be published anonymously - just let us know!


(?) "crypt" function in Linux

From Ben Okopnik

Answered By

Just a little while ago, I needed to use the "crypt" program, so well-known in other Unices, to encode a text file (for those of you unfamiliar with it, it encrypts the contents of a file using a password that you supply. A fairly useful little utility when you want just a bit of added security on a publicly-readable file.) Imagine my surprise when I found that Linux does not have one! Once again, it's Perl to the rescue.
This version follows the syntax of the original "crypt", although I'm certain that the algorithm is different. The encryption and the decryption are symmetric, meaning that the same syntax is used for both (with the obvious exception of the relevant filenames):

# This encrypts the contents of "mysecret.txt" using "iAMw0tIam" as the
# password and saves the results to "mysecret.encrypted".
crypt iAMw0tIam < mysecret.txt > mysecret.encrypted

# This prints out the decrypted contents of "mysecret.encrypted" to the
# screen.
crypt iAMw0tIam < mysecret.encrypted

# This decrypts the contents of "mysecret.encrypted" and writes the results
# to "mysecret.decrypted".
crypt iAMw0tIam < mysecret.encrypted > mysecret.decrypted
Long passwords are preferable to short ones for better security; "crypt" accepts them without a problem, provided that any password containing spaces or other "weird characters" is quoted (preferably in single quotes).

crypt 'Praeterea, censeo Carthaginem esse delendam.' < file > file.enc
As always, bug reports, comments, and piles of diamonds are welcome. :)

See attached crypt.perl.txt

Ben Okopnik


This page edited and maintained by the Editors of Linux Gazette Copyright © 2001
Published in issue 71 of Linux Gazette October 2001
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/


[ Table Of Contents ][ Answer Guy Current Index ] greetings   1   2   3   4   5   6   7   8 [ Index of Past Answers ]