How to encrypt a wmf.

Hi Experts,

I have a directory containg 100 metafiles.

I only want my application to be able to use them, what is the best way to do this.

200 points for best example.
Asw


LVL 1
AswAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rwilson032697Connect With a Mentor Commented:
Sure!

I hope it all goes well...

Cheers,

Raymond.
0
 
JoeBoothCommented:
Once possibility would be to stored them in an encrypted ZIP file and use one of the zip components to extract the ones you need at either program start-up or on demand.

This would also allow you to reduce your distribution size.
0
 
intheCommented:
maybe over the top but theres good encryption stuff here:(not sure about files)
http://crypto-central.com/index.html
most have a freware version , as well as commercial.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rwilson032697Commented:
Well, I guess it all depends on how badly you want to protect them. There are a ton of encryption components on the Delphi Super Page (http://sunsite.icm.edu.pl/delphi) all of which would give you good protection.

On the other hand these are probably overkill, and a simple bit twiddling algorithm would probably suffice, something like an partially overlapped XOR with multiple XOR keys is simple to implement, and relatively hard to break unless someone disassembles your program. But in that case it doesn't matter as any method you use will be breakable (eg: they could find your ZIP file password, unzip the zip file and have your meta files...)

Cheers,

Raymond.

0
 
AswAuthor Commented:
Hi JoeBooth, Inthe, rwilson,

Thank for your comments.

I'm not looking to shoot a mouse with an elephant gun, only to stop the end user from giving my files to others.

These files took months to draw.

Asw
0
 
rwilson032697Commented:
In that case the overlapped XOR would probably work for you. Something like this:

1. Decide on x 32-bit XOR keys (your girlfriends birthday etc), where x is a number you think gives enough layers to be secure enough for you.

2. Write VERY simple routine which reads a file and XORs it with a key.

3. Run the routine over the file x times, shifting each key by some number of bits (or make it simple and shift by a number of bytes). What this means is that a key is applied from byte 2 (say) in the file rather than byte 0 all the time.

The result is a file which won't succumb to a brute force XOR attack because of the shifting, but which is simple to decode...

Cheers,

Raymond.

0
 
AswAuthor Commented:
Hi Raymond,

Any chance of a small example.

Asw

0
 
rwilson032697Commented:
OK - here's a routine to XOR a file with a 32 bit key and a multiple of 8 shift.

Procedure XORFile(InFile, OutFile : String;
Key : Integer;
ShiftBy : Integer);

// Shiftby should be in range 0..3

type
  DataArrayType = array[1..maxint - 1] of Byte;

var
  Data : ^DataArrayType;
  fin, fout : file of byte;
  FSize : Integer;
  I : integer;
  KeyVal : Longint;

begin
  assignfile(fin, InFile);
  reset(fin);
  FSize := filesize(fin);
  getmem(Data, FSize);
  blockread(fin, Data, FSize);
  CloseFile(fin);

  KeyVal := Key SHR (ShiftBy * 8);
  for I := ShiftBy to FSize do
    begin
      Data^[I] := Data^[I] XOR (KeyVal AND $ff);
      KeyVal := KeyVal SHR 8;
      if I Mod 4 = 3 then
        KeyVal := Key;
    end;

  assignfile(fout, OutFile);
  rewrite(fout);
  blockwrite(fout, Data, FSize);
  CloseFile(fout);
end;

To decrypt the file perform the same XOR operations in the reverse order.

Cheers,

Raymond.
0
 
edeyCommented:
All great suggestions noted above, though i may like to add another :)

checking at wotsit.org (a great reasource) i found this link to a description of the .wmf file format (http://wotsit.org/cgi-bin/download.cgi?metafile)

as noted in the above file the .wmf head should look like this:

typedef struct tagMETAHEADER {
    WORD  mtType;
    WORD  mtHeaderSize;
    WORD  mtVersion;
    DWORD mtSize;
    WORD  mtNoObjects;
    DWORD mtMaxRecord;
    WORD  mtNoParameters;
} METAHEADER;

so, instead of xoring every bit in each file, it should be simple enough to 'mess with a couple of these variable to produce an invalid header.  This should be a lot faster.

GL
Mike
0
 
kifahCommented:
Hi,
The simplest way is to store them in your application, let's say in a separate form, or even in a DLL.

even will be faster for retriving (no Decryption is needed). and they 100% safe... because who can get them that's mean he get all your source code...

even thoug he still can still capture them by a simple PrtSc from you application when it is running.. unless you handle this....

Best Regards....
0
 
RadlerCommented:
Hi Asw

Well, if this way is OK, let's go:

You can make a resource DLL and link to it doing a RC file like this;
#MyPics.RC

FILE01 RCDATA "MyFile01.wmf"
FILE02 RCDATA "MyFile02.wmf"
.....

-After do it use brcc32.exe (founded at  ..\delphi\bin ) to compile MyPics.rc
- put at your code

{$R Mypics.res}

....
var
Strm := TResourceStream;
begin
Strm:=:= TResourceStream.Create(Application.Handle, 'FILE01', RT_RCDATA);
Strm.SaveToFile('MyFile01.wmf');

end;

T++, Radler.
0
 
RadlerCommented:
Sorry, Where is Application.Handle, put the handle of the library, Ok.

T++, Radler.
0
 
rwilson032697Commented:
Hmmm..

Putting them in the app as resources is about the same as just zipping them up with no password. Any 2-bit resource editor will extract them PDQ!

Cheers,

Raymond.
0
 
rwilson032697Commented:
Thats odd - I got an email saying this Q was answered by Radler, though it seems his previous comment above has morphed into a proposed answer!

Strange!

Cheers,

Raymond.
0
 
AswAuthor Commented:
Hi Radler,

Thank for your proposed answer, but like Raymond has said these would be easy to get at with a res editor.

All I realy want to do is when I fire up my app the files are decrypted and when I close the app the files are encrypted.

Asw
0
 
rwilson032697Commented:
I don't think thats a very good idea, as the files could be copied while the program is running.

You could decrypt each file as it was required to a temporary file, use it and then delete the file. The XORing of a file is going to be pretty quick (unless the WMF is HUGE), so I don't think this will give you any significant performance problems.

Cheers,

Raymond.
0
 
intheCommented:
Hi
here a link to many encryption units:
http://www.torry.ru/vcl/security/

a simple enough one from there would be gbcrypt.zip

Regards Barry

0
 
AswAuthor Commented:
Hi Raymond,

Can you be a bit more specific how I would use your routine, I have not had any experience with XORing .

I have a folder with 100 wmfs in it what would I do.

Asw
0
 
rwilson032697Commented:
You might call the routine I wrote like this (2 calls with different keys, second one shifted by 3 bytes):

This would encrypt fred.wmf.
 
XORFile('fred.wmf', 'temp.wmf', $34231256, 0);
XORFile('fred.wmf', 'fred.wmf', $98378650, 3);

(Of course the XORFile routine could be easily changed to save the extra file read and write...)

To decrypt fred.wmf, and use the decrypted file do the same steps in the reverse order (though I end up with temp.wmf):

XORFile('fred.wmf', 'temp.wmf', $98378650, 3);
XORFile('temp.wmf', 'temp.wmf', $34231256, 0);

Now just use temp.wmf as a wmf file...

So, I would take your 100 wmfs, copy them into a different location, run a little program over them to encrypt them and ship those files with the app.

The app then does the decryption step whenever it wants to use a .WMF file (to be tidy you would write a little wrapper function that hides all this from the app).

Cheers,

Raymond.
0
 
AswAuthor Commented:
Hi Raymond,

Can you type a few lines a an answer
then I will give you the points.

Thanks to all the experts who posted a comment, but raymonds solution was the one I used.

Hay well done earning 200'000 points + Raymond.

Asw
0
 
RadlerCommented:
At the next time I will stay alive all trouhgt the nigth |O)
 
T++, Radler.
0
All Courses

From novice to tech pro — start learning today.