Jump to content


Photo

P6CryptAES Dll wrapped: Encypt with 32 char pw


  • Please log in to reply
11 replies to this topic

#1 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 21 July 2012 - 12:45 AM

This is a wrapper for the P6CryptAES dll, found here. Original binary download here.

It allows encrypting and decrypting "strings" of up to 60k bytes (not necessarily characters, as Game Maker uses UTF-8 encoding - use dll_strlen_delphi_bytes to get the memory usage of a string) and files or arbitrary size with the Advanced Encryption Standard algorithm.

This is wrapped without a recompilation directly in Game Maker - it uses the GM DLL extension.

It exposes the following functions:

  • pc6_encrypt_file(sourceFileName, encryptedTargetFileName, password) -> 0 on success
  • pc6_decrypt_file(encryptedSourceFileName, decryptedTargetFileName, password) -> 0 on success
  • pc6_encrypt_string(string, password) -> encrypted string, do not modify.
  • pc6_decrypt_string(encryptedString, password) -> decrypted string

You need to call p6c_init before using any of these.


Here's the script with documented functions - save this as .gml and import it in your project through Scripts > Import Scripts.
It includes the usage example below as a function called p6c_example. Just call this and look at that script.
 

Download GM P6CryptAES.gml


In case you don't want to download the whole above package, download P6CryptAES.dll here.

Usage example:

p6c_init();
//////////////////// Prepare
var pw, f, es;
pw = "password";
s = "Hello World あいうえお 私"; // source string, demonstrate full UTF-8 cability.
// UTF-8 Encoded to (tool: http://www.rishida.net/tools/conversion/ )
// 48 65 6C 6C 6F 20 57 6F 72 6C 64 20 C3 A4 C3 B6 C3 BC 20 E3 81 82 E3 81 84 E3 81 86 E3 81 88 E3 81 8A E3 80 80 E7 A7 81
// 40 Bytes

show_message("Original string:"+chr(13)+s+chr(13)+string(dll_strlen_delphi_bytes(s))+" bytes in size");

//
f = file_text_open_write("1.txt");
file_text_write_string(f, s);
file_text_close(f);

//////////////////// En- & Decrypt
// Encrypt string
s = pc6_encrypt_string(s, pw);
show_message("Encrypted String (do not modify):"+chr(13)+s);
s = pc6_decrypt_string(s, pw);

// Encrypt file
pc6_encrypt_file("1.txt", "2.txt", pw);
pc6_decrypt_file("2.txt", "3.txt", pw);

// Check string
show_message("Decoded String:"+chr(13)+s);

// Check file
file_text_open_read("3.txt");
s = file_text_read_string(f);
file_text_close(f);
show_message("Decoded File:"+chr(13)+s); 

Notes: You will have problems printing out to the screen or saving the encoded string to files and applying any string operations on it is not recommended (will probably make decryption impossible).
Better work with it using dll_cstring_byte_at and dll_cstring_set_byte_at.

I hope you'll find it useful.
- Paul


Edited by Master Xilo, 23 August 2015 - 02:07 PM.

  • 1

#2 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 21 July 2012 - 08:21 PM

Hey,
I've not gotten any of the functions to work correctly. All I get is errors. For file encryption I had an error:



___________________________________________
EXECUTION ERROR in creation code of room room0
In script pc6_encrypt_file:
Error in code at line 2:
///pc6_encrypt_file(sourceFileName, encryptedTargetFileName, password) -> 0 on successreturn dll_call(global.EncryptFile_P6C_, argument0, argument1, argument2);
^
at position 24: Unknown variable EncryptFile_P6C_


for string encryption too I get an error. Or maybe I didn't do stuff right? I loaded the gml script and then added your gex, then added the dll to the same directory of the gm file but I still get errors for both? How do we correct this? did u even get it to work?
  • 0
When I finish University, I would like to work for a BIG software Company like;SENJEN COMPANY. I'm obsessed with them! Period!

#3 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 21 July 2012 - 09:18 PM

You forgot to call p6c_init();
Sure I got it to work, it would be hard to be sure to have gotten this working without testing.

Edited by Master Xilo, 21 July 2012 - 09:20 PM.

  • 1

#4 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 21 July 2012 - 10:55 PM

You forgot to call p6c_init();
Sure I got it to work, it would be hard to be sure to have gotten this working without testing.

I did call the init script. In fact, I didn't use my own code. I just created an object in the room and copied your p6c_example script and here's the error I got


___________________________________________
ERROR in
action number 1
of Create Event
for object object0:

In script pc6_encrypt_string:
In extension function dll_call:
Error in code at line 4:
   for (i = 0; i < argument_count-1; i+= 1) { // assuming fid.argc == argument_count-1 (everything passed here exc fid)
                   ^
at position 18: Unknown variable argument_count

what's wrong, or ok, can get your gmk and everything including dlls all in one zip?
  • 0
When I finish University, I would like to work for a BIG software Company like;SENJEN COMPANY. I'm obsessed with them! Period!

#5 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 21 July 2012 - 11:28 PM

Which version of Game Maker are you using? Is argument_count highlighted in a code editor when you write it?
Was this just recently introduced? I only tested with Game Maker 8.1.

EDIT: It looks like argument_count was really just added in 8.1. Do you have any reason not to upgrade?

Edited by Master Xilo, 21 July 2012 - 11:31 PM.

  • 1

#6 SenJe0

SenJe0

    GMC Member

  • GMC Member
  • 733 posts

Posted 22 July 2012 - 03:00 AM

Which version of Game Maker are you using? Is argument_count highlighted in a code editor when you write it?
Was this just recently introduced? I only tested with Game Maker 8.1.

EDIT: It looks like argument_count was really just added in 8.1. Do you have any reason not to upgrade?

What do we do now? I need this baaddly. :confused:
u need to do make it that's compatible with v.8.0...please. at least if you know the function of that code, we coould write a similar script and replace that function with it...something of that sort? I don't hav the means to upgrade now.

Edited by SenJe0, 22 July 2012 - 10:32 AM.

  • -1
When I finish University, I would like to work for a BIG software Company like;SENJEN COMPANY. I'm obsessed with them! Period!

#7 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 22 July 2012 - 03:35 PM

Do you have to pay for the 8.0 -> 8.1 upgrade? That wasn't the case with 6.0 -> 6.1 -> 7.0 ...

Anyways, I updated it to work with <8.1 by making it not call any of the functions which use argument_count. You also need to download the latest GM DLL extension (updated it).

Let me know if it works for you too now.
  • 1

#8 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 22 July 2012 - 08:31 PM

Just read: You don't have to pay anything for upgrading from 8.0 to 8.1...

Those of you who have already purchased Game Maker 8, you will be able to upgrade for FREE!


http://glog.yoyogames.com/?p=3190

...
  • 0

#9 van0014

van0014

    GMC Member

  • GMC Member
  • 301 posts
  • Version:GM8.1

Posted 10 March 2013 - 02:10 AM

it works. Save the .gml in UTF-8 and somehow, there won't be any errors.

Download

Both DLL's included (P6CryptAES.dll and oleaut32.dll)

Does anyone know why pc6_decrypt_file always returns 0, even if the password is wrong? i tried using dll_call_ and dll_call but both always return the same numbers.

also, dll_call_ is an undefined script, yet it works??? it just does not return anything

Edited by van0014, 10 March 2013 - 05:09 AM.

  • 0

Proud user of GM 8.1


#10 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 13 July 2014 - 09:18 PM

Fixed link.
  • 0

#11 Alert Games

Alert Games

    GMC Member

  • GMC Member
  • 1119 posts
  • Version:GM8

Posted 06 October 2014 - 02:55 AM

I'm not sure if Im just blind here, or else I can't seem to find where you have the AES key length in the example? I am assuming because I can't find it, that it is using the 128-bit key, and the password should thus be 16 characters in length.


  • 0

#12 Master Xilo

Master Xilo

    GMC Member

  • GMC Member
  • 396 posts
  • Version:GM8

Posted 06 October 2014 - 07:01 AM

The key is in the variable called pw. Its set to password. The algorithm fills up the caracters msiing to get 16 I guess.
  • 0