The following pair of functions can be used with the Crypto plugin in AutoPlay Media Studio 5.0 Professional to blowfish encrypt and decrypt strings.
Note: The Crypto.BlowfishEncrypt and Crypto.BlowfishDecrypt actions only operate on files because blowfish-encrypted data can't be stored in a string without (the encrypted data contains characters that aren't valid string characters). The following two functions get around this limitation by using temporary text files and base64-encoding the encrypted versions so they can be read back in as strings.
I've attached a simple project that demonstrates how to use these two functions (and proves that they workCode:-- Function: BlowfishEncryptString -- Purpose: Blowfish encrypts a string by saving it to a -- temporary file and then base-64 encoding the encrypted -- version to get the encrypted data in string form. -- Returns: The source string blowfish encrypted -- and base64 encoded, or "" if an error occurs. function BlowfishEncryptString(SourceText, Key) -- I've tried to choose filenames that are unlikely to already exist ;) local tempsrc = _TempFolder.."\\ILoveMyMommysChicken.tempsrc"; local tempenc = _TempFolder.."\\ILoveMyMommysChicken.tempenc"; -- Write the source string out to a temporary file TextFile.WriteFromString(tempsrc, SourceText); -- Make sure the TextFile.WriteFromString action was successful -- (If an error occurred, display the error message in a dialog, clean up and abort) local error = Application.GetLastError(); if (error ~= 0) then Dialog.Message("Error", _tblErrorMessages[error] , MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1); File.Delete(tempsrc); return ""; end -- Now blowfish encrypt the file Crypto.BlowfishEncrypt(tempsrc, tempenc, Key); -- Make sure the Crypto.BlowfishEncrypt action was successful local error = Application.GetLastError(); if (error ~=0) then Dialog.Message("Error", _tblErrorMessages[error] , MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1); File.Delete(tempsrc); File.Delete(tempenc); return ""; end -- Now base64 encode the encrypted file and store it in a string local strEncoded = Crypto.Base64EncodeToString(tempenc); -- Make sure the Crypto.Base64EncodeToString action was successful error = Application.GetLastError(); if (error ~=0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1); File.Delete(tempsrc); File.Delete(tempenc); return ""; end -- remove the temp files File.Delete(tempsrc); File.Delete(tempenc); return strEncoded; end -- Function: BlowfishDecryptString -- Purpose: Blowfish decrypts a string that was encrypted -- using the BlowfishEncryptString function. -- Returns: The source string base64 decoded and blowfish -- decrypted, or "" if an error occurs. function BlowfishDecryptString(SourceText, Key) -- I've tried to choose filenames that are unlikely to already exist ;) -- (If you're wondering, I have an Australian friend who says this constantly, -- I can't seem to get this out of my head today) local tempsrc = _TempFolder.."\\ILoveMyMommysChicken.tempsrc"; local tempdec = _TempFolder.."\\ILoveMyMommysChicken.tempdec"; -- base64 decode the string to a temp file Crypto.Base64DecodeFromString(SourceText, tempsrc); -- Make sure the Crypto.Base64DecodeFromString action was successful -- (If an error occurred, display the error message in a dialog, clean up and abort) local error = Application.GetLastError(); if (error ~=0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1); File.Delete(tempsrc); return ""; end -- Now blowfish decrypt the file Crypto.BlowfishDecrypt(tempsrc, tempdec, Key); -- Make sure the Crypto.BlowfishDecrypt action was successful error = Application.GetLastError(); if (error ~=0) then Dialog.Message("Error", _tblErrorMessages[error] , MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1); File.Delete(tempsrc); File.Delete(tempdec); return ""; end -- Read the source string in from the temporary file local strDecrypted = TextFile.ReadToString(tempdec); -- Check if any errors occurred from calling the TextFile.ReadToString action. -- If an error occurred, display it's error message in a dialog message, clean up and abort. error = Application.GetLastError(); if (error ~=0) then Dialog.Message("Error", _tblErrorMessages[error] , MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1); File.Delete(tempsrc); File.Delete(tempdec); return ""; end -- remove the temp files File.Delete(tempsrc); File.Delete(tempdec); return strDecrypted; end). The functions are contained in the Global Functions section and the code that uses them is in the On Click event for the "Test" button.
Requirements:
These functions and the example project require the Crypto plugin to be installed and enabled (go to Project > Plugins and make sure the "Crypto" item is checked).
Note also that these functions are only for use with AutoPlay Media Studio 5.0 Professional Edition. The Standard Edition does not support action plugins.

