Come posso creare un'immagine AES-256 bit usando Automator?

3

Di default Automator usa la crittografia a 128 bit per la creazione dell'immagine. Non voglio aprire l'utilità del disco per tutto il tempo per creare immagini crittografate. Pertanto, ho pensato di utilizzare hdiutil in Automator.

Come definisco il percorso della cartella di origine nel mio flusso di lavoro? Come posso creare un'immagine con la massima crittografia utilizzando Automator?

    
posta howdytom 10.06.2018 - 23:56
fonte

2 risposte

4

Non hai bisogno di Automator per farlo. Basta usare il cugino Automators, AppleScript.

  1. Apri Script Editor in /Applications/Utilities
  2. Copia e incolla il codice qui sotto
  3. Vai a File > Esporta
  4. Formato file: Applicazione
  5. Trascina file e cartelle sull'icona (puoi persino aggiungere l'icona al documento per un facile accesso
  6. Inserisci la tua password
  7. I file verranno creati nella stessa directory con un _EncryptedDMG.dmg aggiunto

Codice:

on open myFiles
    set theCount to 1
    display dialog "Enter the password to encrypt" default answer "" with hidden answer
    set myPassword to the text returned of the result as text
    set d to "•"
    set td to ""
    repeat length of myPassword times
        set td to td & d
    end repeat
    display dialog "Verify the password: " & td default answer "" with hidden answer
    set theVerify to the text returned of the result
    if myPassword is theVerify then
        tell application "System Events"
            repeat with myFile in myFiles
                set myPath to the POSIX path of myFile
                set myName to the characters 1 thru ((offset of "." in (name of myFile as text)) - 1) of (name of myFile as text)
                set myContainer to (the POSIX path of (container of myFile))
                do shell script "printf  \"" & myPassword & "\" |  hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & myPath & "' '" & myContainer & "/" & myName & "'"
                do shell script "mv '" & myPath & "' ~/.Trash"
                display notification "File created at " & myContainer & "/" & myName & ".dmg. Original file deleted." with title "Encryption Complete" subtitle "File " & theCount & " of " & (length of myFiles) sound name "glass"
            end repeat
        end tell
    else
        display dialog "Error: Passwords did not match"
    end if
end open

Se desideri aggiungere al menu di scelta rapida copia e incolla il seguente codice in un'azione "Esegui Apple Script".

on run {myFiles, parameters}
    set theCount to 1
    display dialog "Enter the password to encrypt" default answer "" with hidden answer
    set myPassword to the text returned of the result as text
    set d to "•"
    set td to ""
    repeat length of myPassword times
        set td to td & d
    end repeat
    display dialog "Verify the password: " & td default answer "" with hidden answer
    set theVerify to the text returned of the result
    if myPassword is theVerify then
        tell application "System Events"
            repeat with myFile in myFiles
                set myPath to the POSIX path of myFile
                set myName to the characters 1 thru ((offset of "." in (name of myFile as text)) - 1) of (name of myFile as text)
                set myContainer to (the POSIX path of (container of myFile))
                do shell script "printf  \"" & myPassword & "\" |  hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & myPath & "' '" & myContainer & "/" & myName & "'"
                do shell script "mv '" & myPath & "' ~/.Trash"
                display notification "File created at " & myContainer & "/" & myName & ".dmg. Original file deleted." with title "Encryption Complete" subtitle "File " & theCount & " of " & (length of myFiles) sound name "glass"
            end repeat
        end tell
    else
        display dialog "Error: Passwords did not match"
    end if
end run

Quando si apre Automator, selezionare il menu di scelta rapida e quindi selezionare queste impostazioni

Nota: sarai felice di sentire, macOS Mojave porterà funzionalità simili in modo nativo. C'è una password aggiunta nel menu di scelta rapida che blocca e crittografa il file in modo simile a come questa applicazione, ma ancora non c'è la barra di avanzamento.

Nota [2]: questo script non funzionerà se la cartella contiene file bloccati (File > Informazioni > Bloccato).

    
risposta data 11.06.2018 - 05:12
fonte
2

Ho sentito che c'erano abbastanza differenze tra la mia soluzione e l'altra risposta postata, in modo da offrire questo script come un'altra risposta al post originale.

Salva questo script come applicazione nell'app ScriptEditor

Questo script consente all'utente di rilasciare più file o cartelle, direttamente sull'icona di questa applicazione ... Inoltre offre all'utente l'opzione di conservare o eliminare i file o le cartelle originali.

Se questa applicazione di script viene eseguita nel modo normale facendo doppio clic sull'applicazione, all'utente viene offerta l'opzione se scegliere file singoli o multipli o scegliere cartelle singole o multiple da elaborare. Inoltre, all'utente viene data l'opzione di cancellare o conservare i file originali.

Questo è stato testato usando l'ultima versione di macOS High Sierra

UPDATE: questo codice è stato modificato per gestire i file o le cartelle bloccate

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

global deleteFiles, isTrue, theCount, myPassword, theName

on open theFiles
    --HANDLE THE CASE WHERE THE SCRIPT IS LAUNCHED BY DROPPING FILES ONTO APP ICON
    repeat with i from 1 to count of theFiles
        set thisItem to item i of theFiles
        tell application "Finder"
            if locked of (get properties of thisItem) then
                set locked of thisItem to false
            end if
        end tell
        set isTrue to missing value
        set theCount to 0
        set theName to missing value
        set theFolder to thisItem
        tell application "Finder"
            set theContainer to container of theFolder as alias
            set theName to name of (get properties of theFolder)
        end tell
        run my setPassword
        run my keepOriginals
        set myPath to POSIX path of theFolder
        set theContainer to POSIX path of theContainer
        do shell script "printf  \"" & myPassword & "\" |  hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & ¬
            myPath & "' '" & theContainer & theName & "_Encrypted'"
        if deleteFiles = true then
            tell application "Finder" to delete theFolder
        end if
    end repeat
end open

on run
    --HANDLE THE CASE WHERE THE SCRIPT IS LAUNCHED  DROPPED FILES
    activate
    set theChoice to display dialog ¬
        "WOULD YOU LIKE TO CHOOSE FILES OR FOLDERS?" buttons {"Cancel", "Choose Files", "Choose Folders"} ¬
        default button ¬
        "Choose Folders" cancel button ¬
        "Cancel" with title ¬
        "Make Your Choice" with icon 1 ¬
        giving up after 20
    if button returned of theChoice is "Choose Files" then
        run my chooseFiles
    else if button returned of theChoice is "Choose Folders" then
        run my chooseFolders
    else if button returned of theChoice is "" then
        return
    end if
end run

script chooseFiles
    activate
    set theFiles to (choose file with multiple selections allowed)
    repeat with i from 1 to count of theFiles
        set thisItem to item i of theFiles
        tell application "Finder"
            if locked of (get properties of thisItem) then
                set locked of thisItem to false
            end if
        end tell
        set isTrue to missing value
        set theCount to 0
        set theName to missing value
        set theFolder to thisItem
        tell application "Finder"
            set theContainer to container of theFolder as alias
            set theName to name of (get properties of theFolder)
        end tell
        run my setPassword
        run my keepOriginals
        set myPath to POSIX path of theFolder
        set theContainer to POSIX path of theContainer
        do shell script "printf  \"" & myPassword & "\" |  hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & ¬
            myPath & "' '" & theContainer & theName & "_Encrypted'"
        if deleteFiles = true then
            tell application "Finder" to delete theFolder
        end if
    end repeat
end script

script chooseFolders
    activate
    set theFiles to (choose folder with multiple selections allowed)
    repeat with i from 1 to count of theFiles
        set thisItem to item i of theFiles
        try
            tell application "Finder"
                set locked of every item of entire contents of thisItem to false
            end tell
        end try
        set isTrue to missing value
        set theCount to 0
        set theName to missing value
        set theFolder to thisItem
        tell application "Finder"
            set theContainer to container of theFolder as alias
            set theName to name of (get properties of theFolder)
        end tell
        run my setPassword
        run my keepOriginals
        set myPath to POSIX path of theFolder
        set theContainer to POSIX path of theContainer
        do shell script "printf  \"" & myPassword & "\" |  hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & ¬
            myPath & "' '" & theContainer & theName & "_Encrypted'"
        if deleteFiles = true then
            tell application "Finder" to delete theFolder
        end if
    end repeat
end script

script failedPassVerify
    activate
    display dialog ¬
        "You Have Unsuccessfully Verified Your Password 3 Times In A Row... Please Try Again Later" buttons {"OK"} ¬
        default button ¬
        "OK" with title ¬
        "UNSUCCESSFUL PASSWORD VERIFICATION" with icon 0 ¬
        giving up after 10
    quit me
end script

script keepOriginals
    set keepOrDelete to display dialog ¬
        ("Would You Like To Delete The Original Item... " & theName & "?") buttons {"DELETE ORIGINALS", "KEEP ORIGINALS"} ¬
        default button 2 ¬
        with title ¬
        "KEEP OR DELETE ORIGINALS?" with icon 0 ¬
        giving up after 30
    if button returned of keepOrDelete is "DELETE ORIGINALS" then
        set deleteFiles to true
    else if button returned of keepOrDelete is "KEEP ORIGINALS" then
        set deleteFiles to false
    else if button returned of keepOrDelete is "" then
        set deleteFiles to false
    end if
end script

script setPassword
    repeat until isTrue = true
        activate
        set myPassword to text returned of (display dialog ¬
            ("ENTER THE PASSWORD TO ENCRYPT DISK IMAGE " & theName) default answer "" with hidden answer)
        activate
        set myPassword2 to text returned of (display dialog ¬
            "PLEASE VERIFY YOUR PASSWORD" default answer "" with hidden answer)
        set isTrue to myPassword2 = myPassword
        if isTrue = false then
            set theCount to theCount + 1
            if theCount = 3 then
                run my failedPassVerify
            end if
            activate
            display alert ¬
                "PASSWORDS DO NOT MATCH" message ¬
                "PASSWORDS DO NOT MATCH" giving up after 3
        end if
    end repeat
end script
    
risposta data 13.06.2018 - 06:19
fonte

Leggi altre domande sui tag