AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: Crypto (https://forums.alliedmods.net/showthread.php?t=319623)

iNvectus 11-11-2019 12:21

Module: Crypto
 
4 Attachment(s)
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

gabuch2 11-12-2019 07:49

Re: Module: Crypto
 
Why should I use this vs the native hash_string()?

iNvectus 11-13-2019 01:45

Re: Module: Crypto
 
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.

thEsp 11-15-2019 15:45

Re: Module: Crypto
 
Good job. Having a dedicated module isn't a big problem.

JocAnis 11-15-2019 19:47

Re: Module: Crypto
 
Can anyone give one good example of using hash_string ? Maybe for pass (login system) for mysql?

gabuch2 11-15-2019 19:52

Re: Module: Crypto
 
Quote:

Originally Posted by JocAnis (Post 2673081)
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.

sonshitsu 08-25-2022 08:48

Re: Module: Crypto
 
Quote:

Originally Posted by iNvectus (Post 2672647)
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.


All times are GMT -4. The time now is 21:06.

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