|
Cookbook /
WikiShCryptSummary: Provide encryption/decryption for WikiSh commands and in other contexts
Version: 2008-05-05
Prerequisites: WikiSh, MCRYPT extension to PHP
Status: Alpha
Maintainer: Peter Bowers
Categories: MarkupExpressions Security
Download: WikiShCrypt.phpΔ
Questions answered by this recipe
DescriptionProvide encryption/decryption for WikiSh commands and elsewhere. InstallationThere is an extension to PHP called MCRYPT which provides excellent encryption capabilities. WikiShCrypt depends on this extension. However, it is not installed by default on many servers. Here are BRIEF instructions on how to install (it is beyond the scope of this document to describe in greater detail):
The PHP script WikiShCrypt.phpΔ must be placed in your cookbook directory and the appropriate line included in your config.php after including WikiSh.php: include_once('$FarmD/cookbook/WikiShCrypt.php');
$WikiShVars['CRYPT_IV_FILE'] = 'TEXTFILE--CryptIV.txt';
You must make sure that you have read/write privileges to the page or file specified for CRYPT_IV_FILE the first time you attempt to encrypt or decrypt something. Thereafter you will need only read privileges. Please note the necessity of passing all 4 levels of security in order to obtain read or write privilege for a given page or file. If encryption is all you are working on then this configuration should suffice:
include_once('cookbook/WikiSh.php');
include_once('cookbook/WikiShCrypt.php');
$WikiShVars['CRYPT_IV_FILE'] = 'TEXTFILE--CryptIV.txt';
$EnableWikiShTextRead = true;
$WikiShTextReadList = array('CryptIV.txt');
$EnableWikiShTextWrite = true;
$WikiShTextWriteList = array('CryptIV.txt');
You can specify any filename or a pagename for the CRYPT_IV_FILE value, but be aware that you do NOT want to lose this file. It will be automatically created the first time you do any encryption or decryption. Thereafter that file/page will be read and the value used each time any encryption or decryption is done. If you lose that file then all encrypted files, well, not to be overly dramatic, but they will remain encrypted forever. Be forewarned - BACK IT UP! Also if you change from one algorithm or mode of encryption to another you should decrypt all encrypted files and then delete the CRYPT_IV_FILE file (or rename it or respecify a different value in your config.php), then change the algorithm/mode, and then encrypt some other piece of data in order to recreate the IV for the new encryption type. There are also 4 configuration variables used in setting the encryption algorithm and mode. They correspond to the 4 arguments to mcrypt_generic_init(). They are (in order):
These variables (with the others) can be set in config.php via $WikiShVars[] or in the profile/rc pages to give page-level administrative control. UsageHere is how you use the encryption/decryption capabilities:
If I wanted to take a page I had created in Session.MyPrivatePage and place this virtual page in a "real" page MyGroup.MyPrivatePage but I wanted it to be encrypted here is what I would do:
Obviously putting a command like this with the password in cleartext on a page is not ideal. So normally this would be accomplished by creating a form for the user to enter the password, placing that password in a variable, and then specifying the password by means of that variable:
As a convenient side effect of the implementation method of all reading/writing within WikiSh, you can easily encrypt or decrypt a page or a file by simply copying it overtop of itself: Encrypting:
Decrypting:
Release Notes
See AlsoKnown problems
ContributorsComments |