Hi
I'm looking for a way to encrypt some datas (save file, media...).
A lot of technic use a key (string or array) to encrypt the datas.
But, I have seen that, in the bytcode, we can see the key.
Example of code :
// Project: encode
// Created: 2017-10-29
SetWindowTitle( "encode" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
UseNewDefaultFonts( 1 )
Global tx$ = "A little text to test if you see it on the bytecode."
#constant Ckey2 = "AnotherKey321"
txt$ = EncodeString(tx$)
do
Print( ScreenFPS() )
Sync()
loop
Function EncodeString(MyString$)
key$ = "My_super_key"
hash$ = Sha1(MyString$ + key$)
Endfunction hash$
If you compile this code, in the bycode you will see :
main.agc encode2 A little text to test if you see it on the bytecode.
AnotherKey321 My_super_keyH$
Yes, in the bycode, we can see the 2 keys, which isn't very protected ^^.
What do you think about this technic : to use chr() instead of the string.
For example :
"My_super_key" = Chr(77)+Chr(121)+Chr(95)+Chr(115)+Chr(117)+Chr(112)+Chr(101)+Chr(114)+Chr(95)+Chr(107)+Chr(101)+Chr(121)
The new code :
// Project: encode
// Created: 2017-10-29
SetWindowTitle( "encode" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
UseNewDefaultFonts( 1 )
Global tx$
tx$ = Chr(65)+Chr(32)+Chr(108)+Chr(105)+Chr(116)+Chr(116)+Chr(108)+Chr(101)+Chr(32)+Chr(116)+Chr(101)+Chr(120)+Chr(116)+Chr(32)+Chr(116)+Chr(111)+Chr(32)+Chr(116)+Chr(101)+Chr(115)+Chr(116)+Chr(32)+Chr(105)+Chr(102)+Chr(32)+Chr(121)+Chr(111)+Chr(117)+Chr(32)+Chr(115)+Chr(101)+Chr(101)+Chr(32)+Chr(105)+Chr(116)+Chr(32)+Chr(111)+Chr(110)+Chr(32)+Chr(116)+Chr(104)+Chr(101)+Chr(32)+Chr(98)+Chr(121)+Chr(116)+Chr(101)+Chr(99)+Chr(111)+Chr(100)+Chr(101)+Chr(46)
// "A little text to test if you see it on the bytecode."
#constant Ckey2 = Chr(65)+Chr(110)+Chr(111)+Chr(116)+Chr(104)+Chr(101)+Chr(114)+Chr(75)+Chr(101)+Chr(121)+Chr(51)+Chr(50)+Chr(49) // "AnotherKey321"
txt$ = EncodeString(tx$)
do
Print( ScreenFPS() )
Print( tx$ )
Sync()
loop
Function EncodeString(MyString$)
// key$ = "My_super_key"
key$ = Chr(77)+Chr(121)+Chr(95)+Chr(115)+Chr(117)+Chr(112)+Chr(101)+Chr(114)+Chr(95)+Chr(107)+Chr(101)+Chr(121)
hash$ = Sha1(MyString$ + key$)
Endfunction hash$
And now, in the bytecode, we don't see anything (no key$)
.
It's a good idea to hide key$, sensible text, but event Ip$ for server for example
how to get those chr() ?
Like that :
// to change a text in a serie of chr()
tx$ = "A little text to test if you see it on the bytecode."
For i=1 To Len(tx$)
a = Asc(Mid(tx$,i,1))
result$ = result$ +"Chr("+Str(a)+")+"
Next
Log(result$) // here you can save it in a text file if you prefer.
What do you think about that ?
Cheers
AGK2 tier1 - http://www.dracaena-studio.com