Encrypt/Decrypt jpeg image/binary file

wackywoo105

Registered User.
Local time
Today, 09:46
Joined
Mar 14, 2014
Messages
203
I am looking for a function that will allow me to encrypt/decrypt single image files as and when required. I have built my own simple one to encrypt a string that will be stored in a filename as all the ones I found created unusable filenames.

However I don’t know where to start with the image file encryption.

(And if anyone has a better way to encrypt a string that can be used in a file name that would be great too. My method is a bit basic).

 
I might be off on a tangent here... but 2 possible solutions:

For pure encryption you could use Winzip:

Public Function WinzipPasswordProtect(strfilename As String, strPassword As String)

PROC_DECLARATIONS:
Const sProc_Name As String = "WinzipPasswordProtect"
Dim strWinzip As String
Dim strZipFile As String
Dim strWinzipCmd As String

PROC_START:
On Error GoTo PROC_ERROR

PROC_MAIN:

DoCmd.SetWarnings False

'Name winzip file same as file to be zipped
strZipFile = Left(strfilename, (InStr(1, strfilename, ".", vbTextCompare) - 1)) & ".zip"

'Winzip program path
strWinzip = "C:\Program Files\WinZip\Winzip64.exe "

strWinzipCmd = strWinzip & " -a -ex -s" & strPassword & " """ & strZipFile & """ """ & strfilename & """"
Call Shell(strWinzipCmd)


PROC_EXIT:
On Error Resume Next
Exit Function

PROC_ERROR:

MsgBox "Error: " & Err.Description
Resume PROC_EXIT

I just checked it with the evaluation version of Winzip (you'll need to update the path to the directory where your version would sit) and it still works, but it isn't fully automated. If you are just after a password generator to encrypt the name and still be valid you could use the following:

Option Compare Database

Public Function GeneratePWD() As String
'******************************************************************
'* Generate an 8 character pseudo random password in the format
'* [A-Z][a-z][special char][0-9][special char][A-Z][a-z][0-9]
'* This gives 24,174,030,400 combinations to guess at.
'******************************************************************
Dim i As Integer
Dim iSlot As Integer
Dim sSigns As String
Dim sPwd As String
Dim dblSeed As Double

dblSeed = Timer * CDbl(Date)

sPwd = ""

Randomize dblSeed
sPwd = Chr(Int((90 - 65) * Rnd + 65)) 'A-Z
dblSeed = dblSeed * CDbl(Date)
Randomize dblSeed
sPwd = sPwd & Chr(Int((57 - 48) * Rnd + 48)) '0-9
dblSeed = dblSeed * CDbl(Date)
Randomize dblSeed
sPwd = sPwd & Chr(Int((57 - 48) * Rnd + 48)) '0-9
dblSeed = dblSeed * CDbl(Date)
Randomize dblSeed
sPwd = sPwd & Chr(Int((57 - 48) * Rnd + 48)) '0-9
dblSeed = dblSeed * CDbl(Date)
Randomize dblSeed
sPwd = sPwd & Chr(Int((57 - 48) * Rnd + 48)) '0-9
dblSeed = dblSeed * CDbl(Date)
Randomize dblSeed
sPwd = sPwd & Chr(Int((90 - 65) * Rnd + 65)) 'A-Z
dblSeed = dblSeed * CDbl(Date)
Randomize dblSeed
sPwd = sPwd & Chr(Int((90 - 65) * Rnd + 65)) 'A-Z
dblSeed = dblSeed * CDbl(Date)
Randomize dblSeed
sPwd = sPwd & Chr(Int((57 - 48) * Rnd + 48)) '0-9

GeneratePWD = sPwd

End Function

If this doesn't help you may have to be more specific to weed out ppl like me!! ;-)
 
Thank you. I have started looking at zip and it also has the advantage of compression. Most examples I can find don't include password which is what I want.
 

Users who are viewing this thread

Back
Top Bottom