Re: PictureBox and images

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



As I understand you need to prevent average users (not specialists in
cryptography, where compiling into executable wouldn't help anyway) from
viewing pictures. In this case you can try the following solution. It is
simple and doesn't require to make your executable to be of enormous size.
It doesn't require any sacrifice in terms of performance as well.

Idea is in that you need to "damage" image files in the way known to you
only and it should be reversible. In other words, you change beginning of
the image to something else, which makes format of the file unrecognizable.
This change must be done using some symmetrical algorithm and you can use
any of available encryption algorithms. The one I give you as a sample is
not really strong cryptographically but I am sure should be enough for you.
The main advantage of symmetric encryption in this case is in that it will
reverse encrypted data back to its original state, when applied for the
second time.

First you should prepare your images - encrypt them using InitialEncode.
Don't repeat it twice, because this way you return to original state (to be
precise, you should apply this procedure odd number of times to encrypt and
even number to decrypt).

Then you are ready to read any of encrypted files using FileIntoPicture. For
testing purposes I've created a folder with one jpg file. Then I placed two
buttons and one picturebox into form. First button is for initial
encryption - as I said use just once.

Second button to load the image to picturebox. Try to open the image outside
of the application using any image processing application.

You should change path to the folder and you can change PWD and number of
bytes to be encrypted to the value you think is strong enough.

Please make backup copies of your files before using this technique. Make
intensive tests to be sure it works in any case (with any of your files).

Important thing to mention - you should avoid concurrent reading of the same
file by multiple instances of your application. If it is possible, then you
should implement some mechanism to prevent double encryption and double
decryption by different instances.


Option Explicit
Const IMG_FOLDER = "C:\My Documents\My Pictures\Test\"
Const MY_PWD As String = "mypwd"
Const LEN_DECRYPT As Long = 50 'number of bytes to encrypt

Private Sub Command1_Click()
Call InitialEncode(IMG_FOLDER)
End Sub

Private Sub Command2_Click()
Dim sFile$
'use the first file in the folder just for testing purposes
sFile = IMG_FOLDER & Dir$(IMG_FOLDER & "*.jpg", vbNormal)
call FileIntoPicture(sFile)
End Sub

private sub FileIntoPicture(sFile as string)
'decrypt file before reading
Call EncryptFile(sFile)
Set Picture1.Picture = LoadPicture(sFile)
'encrypt back
Call EncryptFile(sFile)
end sub


'use this proc only one time, when you prepare your images
'don't apply again cause you will reverse encoding
'in fact this procedure don't need to be in your application
'and can be placed in some separate project as long as you use the same
'encryption algorithm and the same keyword (password/challenge)
Private Sub InitialEncode(sFolder As String)
Dim sFile As String
sFile = Dir$(sFolder & "*.jpg", vbNormal)
Do While LenB(sFile)
Call EncryptFile(sFolder & sFile)
sFile = Dir$()
Loop
End Sub


'in fact this proc will encrypt decrypted file and decrypt encrypted one
Private Sub EncryptFile(sFile As String)
Dim iFile%
Dim arTxt() As Byte

iFile = FreeFile
Open sFile For Binary Access Read Write As #iFile
ReDim arTxt(LEN_DECRYPT - 1)
Get iFile, 1, arTxt()
arTxt = Encrypt(arTxt(), MY_PWD)
Put iFile, 1, arTxt()
Close iFile
End Sub

'the same procedure is used for encryption and decryption
' arSecret array of bytes you wish to encrypt or decrypt.
' Password$ = the password with which to encrypt the string.
Public Function Encrypt(arSecret() As Byte, Password As String) As Byte()
Dim L&, i&, Char%
Dim arTmp() As Byte
arTmp = arSecret

L = Len(Password)
For i= 0 To UBound(arTmp)
Char = Asc(Mid$(Password, (i Mod L) - L * ((i Mod L) = 0), 1))
arTmp(i) = arTmp(i) Xor Char
Next i
Encrypt = arTmp
End Function

Dmitriy,
MCSD

"jack" <jack@xxxxxxxxxxx> wrote in message
news:O3WyYxhNFHA.2520@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I have 30 different jpeg images that I display in a picturebox based on
> user input. I want to include these images inside the exe so the user
> does not have access to them. Is there a way to do this?
>
> Thanks
>


.



Relevant Pages

  • Re: Need help decrypting
    ... Just a brief look: in your encrypt function you ... > I'm wondering if somebody can help me figure out how to decrypt data. ... > Private Sub Encryptpwd() ... > Dim ms As New MemoryStream ...
    (microsoft.public.dotnet.security)
  • Decrypting data
    ... I'm wondering if somebody can help me figure out how to decrypt data. ... to be able to encrypt data but have not been able to decrypt the very data ... Private Sub Encryptpwd() ... hoping I have better luck here. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: VB SaveSetting
    ... be able to encrypt the registry entries. ... In your case I would read your EXE into a string and then look for the ... Private Sub Command1_Click ... While Pos> 0 ...
    (comp.lang.basic.visual.misc)
  • Re: Need help decrypting
    ... I changed the password in Encrypt just before I posted. ... > I'm wondering if somebody can help me figure out how to decrypt data. ... > Private Sub Encryptpwd() ... > Dim ms As New MemoryStream ...
    (microsoft.public.dotnet.security)
  • Need help decrypting
    ... I'm wondering if somebody can help me figure out how to decrypt data. ... to be able to encrypt data but have not been able to decrypt the very data ... Private Sub Encryptpwd() ... I would very much appreciate someone setting me straight on this issue. ...
    (microsoft.public.dotnet.security)