It is currently Sun Jan 24, 2021 10:52 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: how can i crypt game assets and load ?
PostPosted: Sun Jan 10, 2021 6:32 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Dec 04, 2015 9:26 pm
Posts: 292
hello everyone !

i am trying to crypt game assets 3d, sounds and texture .

is there any way to encrypt all assets and import into my game in pb?


Top
 Profile  
Reply with quote  
 Post subject: Re: how can i crypt game assets and load ?
PostPosted: Sun Jan 10, 2021 8:20 am 
Offline
Addict
Addict
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 804
U could use the AES Cipher

Here is some code i wrote (Unicode):
Code:

EnableExplicit

Procedure.i CryptBuffer(*Buffer,Length.i,Key.s,Decrypt.i = #False)
  Protected *key
  Protected *block
  If Key And *Buffer And Length > 15
    *key = Ascii(Key + Space(8))
    If *key
      *block = AllocateMemory(Length)
      If *block
        If Decrypt
          If AESDecoder(*Buffer,*block,Length,*key,128,#Null,#PB_Cipher_ECB)
            FreeMemory(*key)
            ProcedureReturn *block
          EndIf
        Else
          If AESEncoder(*Buffer,*block,Length,*key,128,#Null,#PB_Cipher_ECB)
            FreeMemory(*key)
            ProcedureReturn *block
          EndIf
        EndIf
        FreeMemory(*block)
      EndIf
      FreeMemory(*key)
    EndIf
  EndIf
  ProcedureReturn #Null
EndProcedure

Procedure.i Main()
  Protected *encrypt
  Protected *decrypt
  Protected dummy.s
  dummy = "Hello World!"
  *encrypt = CryptBuffer(@dummy,StringByteLength(dummy) + 2,"Password")
  If *encrypt
    *decrypt = CryptBuffer(*encrypt,MemorySize(*encrypt),"Password",#True)
    If *decrypt
      ShowMemoryViewer(*decrypt ,MemorySize(*decrypt))
      FreeMemory(*decrypt)
    EndIf
    FreeMemory(*encrypt)
  EndIf
  ProcedureReturn
EndProcedure

Main()

End


Edit:
I dont know about the loading part.
Ogre is unable to load stuff from memory iirc.


Top
 Profile  
Reply with quote  
 Post subject: Re: how can i crypt game assets and load ?
PostPosted: Sun Jan 10, 2021 12:11 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 689
Location: Germany, Saarbrücken
Why do you want to encrypt it? The key to decrypt the data would be in the app anyway.

_________________
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: how can i crypt game assets and load ?
PostPosted: Sun Jan 10, 2021 6:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 422
Location: Pandora
Well, for textures, as sam ple, you can just XOR randomize the image in memory.
For this you set RandomSeed() to a starting value and create as many randoms as you need.
Then you save it and load it the other way around.
Otherwise it is like Nick says.
The only way to get a handle this, is to dig very deep into the bag of tricks.
A Hint.
With AES you don't create a plain text password.
Also an Asccii password shortens the key with AES128 to 8 bytes.
But I think for a few textures or other this is little relevant.

_________________
地球上の平和


Top
 Profile  
Reply with quote  
 Post subject: Re: how can i crypt game assets and load ?
PostPosted: Sun Jan 10, 2021 6:41 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 689
Location: Germany, Saarbrücken
Saki wrote:
Well, for textures, as sam ple, you can just XOR randomize the image in memory.
For this you set RandomSeed() to a starting value and create as many randoms as you need.

Using a random seed is not encryption!
Saki wrote:
Then you save it and load it the other way around.

Also randomizing the image's content and then saving it will result in a very bad image quality if you save it in a compressed format like JPG. That's because JPG is optimized for a reasonable image.

_________________
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: how can i crypt game assets and load ?
PostPosted: Sun Jan 10, 2021 7:20 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 422
Location: Pandora
Pre encrypted textures are never saved as JPEGs.
An encrypted or XOR-ed texture also successfully resists any compression.
A lossy compression destroys every encrypted image.
And if he puts the key in the code, he has no working encryption anyway.
Then he has no more than with the XOR, no matter how he does it.

Everything else you put in a structure, encrypt it using the address
of the first entry and sizeof and save it.
Included strings create as FixedString.

_________________
地球上の平和


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye