Encrypt and Decrypt text through AppleScript
If you want an easy way to encrypt and decrypt text using a passphrase, this may be something for you. I’ve written a Java command line tool using Jasypt (an open source library for encryption) that you can call from your AppleScripts.
- Download the Jar file.
- Call it from your AppleScript using a “do shell script” command like this:
-- Encrypt text
set textToEncrypt to quoted form of "Wanna know a secret?"
set passphrase to quoted form of "OurSecretPhrase"
set encryptCommand to "/usr/bin/java -jar /path/to/TextCrypt.jar encrypt " & textToEncrypt & " " & passphrase
set encryptedText to do shell script encryptCommand
-- Decrypt text set
textToDecrypt to "Some∞™¶©©«‹Gibberish"
set passphrase to "OurSecretPhrase"
set decryptCommand to "/usr/bin/java -jar /path/to/TextCrypt.jar decrypt " & textToDecrypt & " " & passphrase
set decryptedText to do shell script encryptCommand
To make it extra convenient, you can use Automator to set up services to encrypt and decrypt with just one keystroke. If you need help setting up a Service workflow in Automator, leave a comment and let me know.
