Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Micha-he authored Feb 23, 2018
1 parent a60fcd5 commit ce928e0
Show file tree
Hide file tree
Showing 10 changed files with 4,164 additions and 0 deletions.
1,332 changes: 1,332 additions & 0 deletions AKrypto.au3

Large diffs are not rendered by default.

Binary file added AKrypto.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions AKrypto.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MainGUI]
WinXPos=448
WinYPos=282
WinWidth=798
WinHeight=366
TreeWidth=250
433 changes: 433 additions & 0 deletions _AES.au3

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions _AESFile.au3
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
; -----------------------------------------------------------------------------
; AES Machine Code UDF File Example
; Purpose: Provide Machine Code Version of AES Algorithm In AutoIt
; Author: Ward
; Changes: Return=1 when all ok ([email protected])
; @error=3 when Source-File not Open ([email protected])
; @error=4 when Destination-File not Open ([email protected])
; -----------------------------------------------------------------------------

; An example for encrypt/decrypt file by AES algorithm with CBC bit padding/CFB/OFB mode
; This code is not intended for real use since it does not provide integrity checking

#Include-once
#Include "_AES.au3"

Global $_AesFileBufferSize = 0x100000

Func _AesEncryptFile($Key, $SrcFile, $DestFile, $Mode = $AES_CBC_MODE, $IV = Default)
If Not FileExists($SrcFile) Then Return SetError(1, 0, 0)

Local $SrcFileSize = FileGetSize($SrcFile)
If $SrcFileSize = 0 Then Return SetError(2, 0, 0)

Local $SrcFileHandle = FileOpen($SrcFile, 16)
If $SrcFileHandle = -1 Then Return SetError(3, 0, 0)
Local $DestFileHandle = FileOpen($DestFile, 2 + 16)
If $DestFileHandle = -1 Then Return SetError(4, 0, 0)

$IV = _AesPrepareIV($IV)
Local $Ctx = _AesEncryptKey($Key)
Local $n = Ceiling($SrcFileSize / $_AesFileBufferSize), $Data

FileWrite($DestFileHandle, $IV)
Switch String($Mode)
Case "CFB", $AES_CFB_MODE
For $i = 1 To $n
$Data = _AesEncryptCFB($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
FileWrite($DestFileHandle, $Data)
Next
Case "OFB", $AES_OFB_MODE
For $i = 1 To $n
$Data = _AesCryptOFB($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
FileWrite($DestFileHandle, $Data)
Next
Case Else
For $i = 1 To $n
If $i <> $n Then
$Data = _AesEncryptCBC($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
Else
$Data = _AesEncryptCBC_Pad($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
EndIf
FileWrite($DestFileHandle, $Data)
Next
EndSwitch

FileClose($SrcFileHandle)
FileClose($DestFileHandle)
Return SetError(0, 0, 1)
EndFunc

Func _AesDecryptFile($Key, $SrcFile, $DestFile, $Mode = $AES_CBC_MODE)
If Not FileExists($SrcFile) Then Return SetError(1, 0, 0)

Local $SrcFileSize = FileGetSize($SrcFile)
If $SrcFileSize < 16 Then Return SetError(2, 0, 0)

Local $SrcFileHandle = FileOpen($SrcFile, 16)
If $SrcFileHandle = -1 Then Return SetError(3, 0, 0)
Local $DestFileHandle = FileOpen($DestFile, 2 + 16)
If $DestFileHandle = -1 Then Return SetError(4, 0, 0)

Local $IV = FileRead($SrcFileHandle, 16)
Local $n = Ceiling($SrcFileSize / $_AesFileBufferSize), $Ctx, $Data

Switch String($Mode)
Case "CFB", $AES_CFB_MODE
$Ctx = _AesEncryptKey($Key)
For $i = 1 To $n
$Data = _AesDecryptCFB($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
FileWrite($DestFileHandle, $Data)
Next
Case "OFB", $AES_OFB_MODE
$Ctx = _AesEncryptKey($Key)
For $i = 1 To $n
$Data = _AesCryptOFB($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
FileWrite($DestFileHandle, $Data)
Next
Case Else
$Ctx = _AesDecryptKey($Key)
For $i = 1 To $n
If $i <> $n Then
$Data = _AesDecryptCBC($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
Else
$Data = _AesDecryptCBC_Pad($Ctx, $IV, FileRead($SrcFileHandle, $_AesFileBufferSize))
EndIf
FileWrite($DestFileHandle, $Data)
Next
EndSwitch

FileClose($SrcFileHandle)
FileClose($DestFileHandle)
Return SetError(0, 0, 1)
EndFunc
Loading

0 comments on commit ce928e0

Please sign in to comment.