Here is something I’ve thrown together:
on ShellEncryption(str, passwd, doEncode, isBase64) -- echo 'plain text' | openssl enc -bf -pass pass:'my password' -salt -e -- echo 'coded text' | openssl enc -bf -pass pass:'my password' -salt -d -- The "echo" command apparently places its argument -- into something called "standard input." The vertical -- slash, ("pipe"), sends the standard input to the -- next command -- set src to "echo " & str's quoted form & " | " -- "openssl" is a command line tool for implementing a -- number of security operations. The "enc" indicates -- that we want the encryption function of openssl. -- set src to src & "openssl enc " -- "enc" is followed by the encryption method to use. -- -- The "man" says, "A beginner is advised to just use a -- strong block cipher in CBC mode such as bf or des3." -- -- "bf" indicates the Blowfish algorithm in CBC mode. -- set src to src & "-bf " -- Apparently, there are these "utilities" that can read -- everything that happens in the command line, (Unix 'ps' -- being an example). This makes the following method of -- indicating the password insecure, (for people who are -- running strange things with names like 'ps'). -- set src to src & "-pass pass:" & passwd's quoted form & " " -- The "man" says "ALWAYS use -salt", whatever the heck it is. -- set src to src & "-salt " -- Encrypt or decrypt: -- if (doEncode) then set src to src & "-e " -- actually, it's the default else set src to src & "-d " end if -- For encryption, we're indicating if the result should be -- returned in Base64 encoding. For decryption, we're -- indicating if the encrypted string is in Base64, ie: it -- needs to be decoded before it can be decrypted. -- if (isBase64) then set src to src & "-a" return do shell script src end ShellEncryption
I was wondering if someone could explain to me about the password. The man page for enc(1) says that Blowfish takes a 128 bit key (16 bytes), by which I understood it to mean the password. Resources I found on the Internet indicate that Blowfish can use a key from 32 to 448 bits, (4 to 56 bytes). As it turns out, however, the command works without fail or complaint no matter what length password I use, including an empty string:
echo ‘hello’ | openssl enc -bf -pass pass:‘’ -salt -e | openssl enc -bf -pass pass:‘’ -salt -d
Why are the various pieces of documentation I’ve found not consistent with one another, and why would an encryption tool allow an empty password?
My ultimate goal would be a user-friendly AppleScript library implementing these 5 basic handlers:
EncryptText( theText, thePassword, useBase64 ) DecryptText( theText, thePassword, useBase64 ) EncryptFile( fileAlias, newFilePath, thePassword, useBase64 ) DecryptFile( fileAlias, newFilePath, thePassword, useBase64 ) FingerprintText( theText ) --> MD5 message digest
Before doing so, however, I want to be sure I understand the security issues involved. I’m not looking for something strong enough to keep out the NSA, but just a “reasonably secure” system for basic “good enough” encryption. The problem with the openssl command is that it has a million options, and despite the fact that “man” stands for “manual,” man has never satisfactorily explained anything to me.