Option Compare Database

'Sean MacKenzie Data Engineering on YouTube
'This software is provided "as is" without warranties of any kind.
'Use at your own risk. The author is not responsible for any damage or data loss.
'Version 0.0.1.3
Const INSTALL_LOCATION = "C:\dev\smackocrypt\v0-1-3\SmackoCrypt.exe" 'CHANGE THIS TO YOUR UNZIPPED EXE LOCATION

Function EncryptOrDecrypt(strEncryptOrDecrypt As String, strValue As String) As String
'Encrypt or decrypt a string using SmackoCrypt
'OPTIONS FOR strEncryptOrDecrypt: Encrypt, Decrypt, GetHash, HashCheck, HashOnlyCheck, GetHashOnly
'HashOnlyCheck and GetHashOnly were added in this version for devs that only want the 256-bit hash and may compare on other systems
On Error GoTo Fn_Error
    Dim objShell As Object, strCommandLine As String
    Dim objExecute As Object, objOutput As Object
    Dim strArgs As Variant
    Dim strReturn As String, strLine As String
    Set objShell = CreateObject("WScript.Shell")
    strArgs = Chr(34) & strEncryptOrDecrypt & Chr(34) & " " & Chr(34) & strValue & Chr(34)
    strCommandLine = INSTALL_LOCATION & " " & strArgs
    Set objExecute = objShell.Exec(strCommandLine)
    Set objOutput = objExecute.StdOut
    While Not objOutput.AtEndOfStream
        strLine = objOutput.ReadLine
        If strLine <> "" Then strReturn = strReturn & strLine & vbNewLine
    Wend
    Set objOutput = Nothing: Set objExecute = Nothing
    Set objShell = Nothing
Fn_Exit:
If Right(strReturn, 2) = vbCrLf Then strReturn = Left(strReturn, Len(strReturn) - 2) 'added from user tests
EncryptOrDecrypt = strReturn
Exit Function
Fn_Error:
    MsgBox "There was an error. (" & Err & ")  " & Error
    Resume Fn_Exit
End Function


Function HashCheck(strValue As String, strHash As String, Optional blnHashOnly = False) As String
'Compare a hash to user input
'Option blnHashOnly included for devs wanting ONLY the 256-bit hash and not the encrypt+hash combo
'These functions should work with no changes for those updating from V0.1.2
On Error GoTo Fn_Error
    Dim objShell As Object, strCommandLine As String
    Dim objExecute As Object, objOutput As Object
    Dim strArgs As Variant
    Dim strReturn As String, strLine As String
    Set objShell = CreateObject("WScript.Shell")
    strArgs = Chr(34) & "Hash" & IIf(blnHashOnly, "Only", "") & "Check" & Chr(34)
    strArgs = strArgs & " " & Chr(34) & strValue & Chr(34)
    strArgs = strArgs & " " & Chr(34) & strHash & Chr(34)
    strCommandLine = INSTALL_LOCATION & " " & strArgs
    Set objExecute = objShell.Exec(strCommandLine)
    Set objOutput = objExecute.StdOut
    While Not objOutput.AtEndOfStream
        strLine = objOutput.ReadLine
        If strLine <> "" Then strReturn = strReturn & strLine & vbNewLine
    Wend
    Set objOutput = Nothing: Set objExecute = Nothing
    Set objShell = Nothing
Fn_Exit:
If Right(strReturn, 2) = vbCrLf Then strReturn = Left(strReturn, Len(strReturn) - 2) 'added from user tests
HashCheck = strReturn
Exit Function
Fn_Error:
    MsgBox "There was an error. (" & Err & ")  " & Error
    Resume Fn_Exit
End Function


