指定された鍵とアルゴリズムでファイルを暗号化します。
#Include <Crypt.au3>
_Crypt_EncryptFile($sSourceFile, $sDestinationFile, $vCryptKey, $iALG_ID)
パラメータ
$sSourceFile | 処理するファイル |
$sDestinationFile | 処理後の保存ファイル |
$vCryptKey | パスワード。CALG_USERKEYフラグが指定されていた場合は鍵のハンドル。 |
$iALG_ID | 使用するアルゴリズム |
返し値
成功: | True |
@errorを0に設定します | |
失敗: | -1を返し、@errorを設定します: |
1 - 鍵の作成に失敗 | |
2 - 処理するファイルを開けない | |
3 - 保存先ファイルを開けない | |
4 - 最終要素の暗号化に失敗 | |
5 - 要素の暗号化に失敗 |
注意
アルゴリズムによっては出力ファイルが入力ファイルより大きくなる場合があります。
関連
_Crypt_EncryptData, _Crypt_DecryptFile, _Crypt_DeriveKey
例
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
$hWnd = GUICreate("File Encrypter", 234, 178, 260, 238)
$InFileLabel = GUICtrlCreateLabel("Input file", 8, 0, 44, 17)
$InFileInput = GUICtrlCreateInput("", 8, 16, 169, 21)
$OutFileLabel = GUICtrlCreateLabel("Output file", 8, 48, 52, 17)
$OutFileInput = GUICtrlCreateInput("", 8, 64, 169, 21)
$InFileButton = GUICtrlCreateButton("...", 184, 16, 35, 20, $WS_GROUP)
$OutFileButton = GUICtrlCreateButton("...", 184, 64, 35, 20, $WS_GROUP)
$AlgoLabel = GUICtrlCreateLabel("Algorithm", 8, 96, 47, 17)
$AlgoCombo = GUICtrlCreateCombo("RC4", 8, 112, 65, 25)
GUICtrlSetData(-1, "3DES|AES 128|AES 192|AES 256|DES|RC2")
$PasswordLabel = GUICtrlCreateLabel("Password", 88, 96, 50, 17)
$PasswordInput = GUICtrlCreateInput("", 88, 112, 129, 21)
$EncryptButton = GUICtrlCreateButton("Encrypt File", 8, 144, 211, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
Global $Increase=0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $InFileButton
$file = FileOpenDialog("Input File", "", "All files (*.*;)")
If $file <> "" Then GUICtrlSetData($InFileInput, $file)
Case $OutFileButton
$file = FileSaveDialog("Output file", "", "Any file (*.*;)")
If $file <> "" Then GUICtrlSetData($OutFileInput, $file)
Case $EncryptButton
$infile = GUICtrlRead($InFileInput)
If Not FileExists($infile) Then
MsgBox(16, "Error", "Input file doesn't exists!")
ContinueLoop
EndIf
$outfile=GUICtrlRead($OutFileInput)
If $outfile="" Then
MsgBox(16,"Error","Please input a output file")
ContinueLoop
EndIf
$algo = 0
Switch GUICtrlRead($AlgoCombo)
Case "3DES"
$algo = $CALG_3DES
Case "DES"
$algo = $CALG_DES
Case "RC2"
$algo = $CALG_RC2
Case "RC4"
$algo = $CALG_RC4
Case "AES 128"
If @OSVersion = "WIN_2000" Then
MsgBox(16, "Error", "Sorry, this algorithm is not available on this system!")
ContinueLoop
EndIf
$algo = $CALG_AES_128
Case "AES 192"
If @OSVersion = "WIN_2000" Then
MsgBox(16, "Error", "Sorry, this algorithm is not available on this system!")
ContinueLoop
EndIf
$algo = $CALG_AES_192
Case "AES 256"
If @OSVersion = "WIN_2000" Then
MsgBox(16, "Error", "Sorry, this algorithm is not available on this system!")
ContinueLoop
EndIf
$algo = $CALG_AES_256
EndSwitch
$password=GUICtrlRead($PasswordInput)
If $password="" Then
MsgBox(16,"Error","Please input a password")
ContinueLoop
EndIf
AdlibRegister("Update",333)
$success=_Crypt_EncryptFile($infile,$outfile,$password,$algo)
If $success Then
MsgBox(0,"Success","Operation succeeded")
Else
Switch @error
Case 1
MsgBox(16,"Fail","鍵の作成に失敗")
Case 2
MsgBox(16,"Fail","Couldn't open source file")
Case 3
MsgBox(16,"Fail","Couldn't open destination file")
Case 4 or 5
MsgBox(16,"Fail","Encryption error")
EndSwitch
EndIf
AdlibUnRegister("Update")
WinSetTitle($hWnd,"","File Encrypter")
EndSwitch
WEnd
Func Update()
Switch Mod($Increase,4)
Case 0
WinSetTitle($hWnd,"","Processing... |")
Case 1
WinSetTitle($hWnd,"","Processing... /")
Case 2
WinSetTitle($hWnd,"","Processing... ・)
Case 3
WinSetTitle($hWnd,"","Processing... \")
EndSwitch
$Increase+=1
EndFunc ;==>Update