Previous - AES Encryption/Decryption Section Home - AES Encryption/Decryption Next - aesDecryptFile


aesEncryptFile ( )

Encrypts a file with AES encryption.

Usage:

aesEncryptFile (object me, string key, string filePathSource, string filePathTarget )

Parameters:

key (string) - A password to encode the file with. The key must be at least 8 characters long

filePathSource (string) - The path to an existing file for encoding

filePathTarget (string) - The path to save the encoded file.

Returns:

(integer) - The success code

Example:

-- example shows exporting every cast member in the internal cast library.
-- these binary files are then encrypted and compressed.
xtRose = xtra("Rosetta").new( )

strTmpFolder = xtRose.sysFolderTemp( )
strLstFiles = []

-- use MD5 to create a really long unique key
strKey = xtRose.md5String( "example" )

repeat with i = 1 to the number of members of castlib 1
  If ( member( i, 1 ).type <> #EMPTY ) Then
    -- make temp file
    strTmpFilePath = xtRose.sysFileTemp( strTmpFolder, "caluRose" )
    
    -- store cast member onto temp file
    If ( xtRose.dirMemExport( member( i, 1 ), strTmpFilePath ) > 0 ) Then
      -- encrypt cast member
      strTmpFilePathSecure = xtRose.sysFileTemp( strTmpFolder, "caluRose" )
      xtRose.aesEncryptFile( strKey, strTmpFilePath, strTmpFilePathSecure )
      
      -- store the filename into a list
      strLstFiles.addAt( strTmpFilePathSecure )
    End IF
    
    xtRose.sysFileDelete( strTmpFilePath )
    
  End If
End Repeat

-- create a new zip file
nFilesCount = strLstFiles.count
If ( nFilesCount > 0 ) Then
  xtRose.zipCreate( the moviepath & "UserSaveData.zip" )
  Repeat with i = 1 to nFilesCount
    strFilePath = strLstFiles[i]
    
    -- extract file name from path
    nLen = strFilePath.length
    Repeat with j = nLen down to 1
      If ( strFilePath.char[j] = "\" ) Then
        strFileName = strFilePath.char[(j+1)..nLen]
        
        -- add to zip file
        xtRose.zipAdd( strFilePath, strFileName )
        Exit Repeat
      End If
    End Repeat
    
    -- delete the secure temp file
    xtRose.sysFileDelete( strFilePath )
    
  End Repeat
  
  -- close the zip file
  xtRose.zipClose( )
End If

Notes:

For compatibility with other applications, developers are urged to use the new functions: aesEncryptString and aesDecryptString. These 2 new functions can create compatible encoding with applications created in Java, C++ and will be cross-platform compatible for use on the Macintosh.

See Also:

aesEncryptString, aesDecryptString, md5String , b64Encode, zipCreate


Previous - AES Encryption/Decryption Section Home - AES Encryption/Decryption Next - aesDecryptFile