Raised This Month: $7 Target: $400
 1% 

Module: Crypto


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iNvectus
Member
Join Date: Sep 2014
Location: Bulgaria
Old 11-11-2019 , 12:21   Module: Crypto
Reply With Quote #1

Description
This module is used for cryptographic purposes. It is made to be simple of usage. You need hash - you get it.

Algorithms
Code:
  • MD5
  • SHA1
  • SHA256
  • SHA3
  • CRC32
Natives
It uses only one native - crypto_hash and has three arguments.

First argument is the algorithm type.
Second argument is the string you want to hash
Third argument is the variable to save the result from the hash.

Code:
native crypto_hash(const iHashType[], const iText[], const iResult[]);

The function has return codes, which of them are:
Code:
  • 0 - Everything is okay, the hash has been done successfully
  • 1 - The hash could not be done, the algorithm is unsupported
  • -1 - Unknown error, should report in this thread or create an issue in Github
Let's see an example usage:
Code:
#include <amxmodx> #include <crypto> public plugin_init() {     register_clcmd("say /crypto", "cmdCrypto"); } public cmdCrypto(id) {     new iHash[256];     new iSuccess = crypto_hash("sha3", "Test", iHash);         if(iSuccess == 0)         client_print(id, print_chat, "Success: %s", iHash);     else         client_print(id, print_chat, "No Success: %d", iSuccess); }

Installation
  1. Install Visual Studio
  2. Download the source code
  3. Open crypto.sln file
  4. Once the solution is opened, go to Build -> Build Solution
  5. Once the compilation is complete, you can go to the project folder and copy the crypto_amxx.dll from Release folder
  6. Place it into amxmodx/modules folder and copy crypto.inc into amxmodx/scripting/include

Changelog
Code:
  • v1.0 - Initial release
Future
I am willing to implement as much algorithms as possible - both encryption/decryption and hashing.

Code:
    • HMAC
    • Caesar Cipher
    • KECCAK
    • Base64 (probably)
Download
You can find the source code available here:
https://github.com/stfkolev/crypto-amxx
Attached Files
File Type: dll crypto_amxx.dll (49.5 KB, 312 views)
File Type: zip crypto-amxx-master.zip (69.0 KB, 292 views)
File Type: inc crypto.inc (472 Bytes, 299 views)
File Type: sma Get Plugin or Get Source (crypto_test.sma - 519 views - 358 Bytes)
__________________
iNvectus is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 11-12-2019 , 07:49   Re: Module: Crypto
Reply With Quote #2

Why should I use this vs the native hash_string()?
__________________
gabuch2 is offline
iNvectus
Member
Join Date: Sep 2014
Location: Bulgaria
Old 11-13-2019 , 01:45   Re: Module: Crypto
Reply With Quote #3

No particular reason, I even encourage all who see this topic to use it instead of this module. It's integrated already. Didn't know it existed, sorry.
__________________
iNvectus is offline
thEsp
BANNED
Join Date: Aug 2017
Old 11-15-2019 , 15:45   Re: Module: Crypto
Reply With Quote #4

Good job. Having a dedicated module isn't a big problem.
thEsp is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 11-15-2019 , 19:47   Re: Module: Crypto
Reply With Quote #5

Can anyone give one good example of using hash_string ? Maybe for pass (login system) for mysql?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 11-15-2019 , 19:52   Re: Module: Crypto
Reply With Quote #6

Quote:
Originally Posted by JocAnis View Post
Can anyone give one good example of using hash_string ? Maybe for pass (login system) for mysql?
If you want to implement a connection system between your game server and say... a forum you might want to hash strings, since that's how most forum systems do it.

For example, for MyBB:

PHP Code:
md5(md5($salt).md5($plain_pass)); 
$plain_pass being the plain text password and $salt a random generated string.

Altough it would be easier to implement a Steam login to bind the IDs to your forum users unless, well, you know.
__________________

Last edited by gabuch2; 11-15-2019 at 19:53.
gabuch2 is offline
sonshitsu
New Member
Join Date: Aug 2022
Old 08-25-2022 , 08:48   Re: Module: Crypto
Reply With Quote #7

Quote:
Originally Posted by iNvectus View Post
Description
This module is used for cryptographic purposes. It is made to be simple of usage. You need hash - you get it.

Algorithms
Code:
  • MD5
  • SHA1
  • SHA256
  • SHA3
  • CRC32
Natives
It uses only one native - crypto_hash and has three arguments.

First argument is the algorithm type.
Second argument is the string you want to hash
Third argument is the variable to save the result from the hash.

Code:
native crypto_hash(const iHashType[], const iText[], const iResult[]);

The function has return codes, which of them are:
Code:
  • 0 - Everything is okay, the hash has been done successfully
  • 1 - The hash could not be done, the algorithm is unsupported
  • -1 - Unknown error, should report in this thread or create an issue in Github
Let's see an example usage:
Code:
#include <amxmodx> #include <crypto> public plugin_init() {     register_clcmd("say /crypto", "cmdCrypto"); } public cmdCrypto(id) {     new iHash[256];     new iSuccess = crypto_hash("sha3", "Test", iHash);         if(iSuccess == 0)         client_print(id, print_chat, "Success: %s", iHash);     else         client_print(id, print_chat, "No Success: %d", iSuccess); }

Installation
  1. Install Visual Studio
  2. Download the source code
  3. Open crypto.sln file
  4. Once the solution is opened, go to Build -> Build Solution
  5. Once the compilation is complete, you can go to the project folder and copy the crypto_amxx.dll from Release folder
  6. Place it into amxmodx/modules folder and copy crypto.inc into amxmodx/scripting/include

Changelog
Code:
  • v1.0 - Initial release
Future
I am willing to implement as much algorithms as possible - both encryption/decryption and hashing.

Code:
    • HMAC
    • Caesar Cipher
    • KECCAK
    • Base64 (probably)
Download
You can find the source code available here:
https://github.com/stfkolev/crypto-amxx
Thank you.
sonshitsu is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode