# Youseful Software - FileMaker sample script
# Script name: Youseful - Encrypt a note
# Plug-in: YsflCrypt.fmx64 (Windows x64)
# Setup: No fields needed. The embedded tutorial-only-password is for this sample. Supply an application password through your credential flow when adapting the script.
# Expected: The dialog says Matched. The encrypted envelope differs each time.
# Format: UTF-8 Script Workspace step listing. Add the steps manually; this is not an importable FileMaker file.
# Lines beginning with # are notes; optionally add them as Comment steps.
# Preserve calculation quotes, backslashes, and paragraph symbols exactly.

Set Variable [ $plain ; Value: "Sample note" ]
Set Variable [ $password ; Value: "tutorial-only-password" ]
Set Variable [ $envelope ; Value: YsflCr_Encrypt ( $plain ; $password ) ]
Set Variable [ $error ; Value: YsflCr_LastError ]
If [ $error <> 0 ]
    Show Custom Dialog [ "Encryption failed" ; YsflCr_LastErrorText ]
    Exit Script [ Text Result: $envelope ]
End If
Set Variable [ $restored ; Value: YsflCr_Decrypt ( $envelope ; $password ) ]
Set Variable [ $error ; Value: YsflCr_LastError ]
If [ $error <> 0 ]
    Show Custom Dialog [ "Decryption failed" ; YsflCr_LastErrorText ]
    Exit Script [ Text Result: $restored ]
End If
Show Custom Dialog [ "Round trip" ; If ( $restored = $plain ; "Matched" ; "Different" ) ]
Set Variable [ $password ; Value: "" ]
