Find Jobs
Hire Freelancers

Convert Encrypt / Decrypt PHP function to Node JS

$10-30 USD

完了済み
投稿日: 9年以上前

$10-30 USD

完了時にお支払い
I have no time to do it so I need someone to convert two functions from PHP code to Node JS. - Make this functions easy to use by creating a module so I can just do something like > var encdec = require('encdec'); < (this is not for redistribute, it is for a private project, so no need manuals nor any extras) and then I can just do > [login to view URL]('myEncryptedString'); < - This one returns a false on fail (which never happen) but try to do it error free as much as possible. /** * 256-bit decryption with mcrypt * MCRYPT_RIJNDAEL_128 is AES-compliant, and MCRYPT_MODE_CBC * Note: ECB mode is inadequate for many purposes because it does not use an IV * * @param string $encrypted receives the encrypted string to decrypt * return bool false on fail, or decrypted string if succeeded */ function myDecrypt ($encrypted) { // salt $salt = '!kqM*Ff7pXe1kBn%9'; // Build a 256-bit $key which is a SHA256 hash of $salt and $password. $key = hash('SHA256', $salt ."LPC9aVs3w8k45vx7oHOxZgoNus3banTGPp5wmhJ6hSnJko9rjB/G5Q1mdhdxjm01q6kK2h44MP5L6DML4nY/uq", true); // Retrieve $iv which is the first 22 characters plus ==, base64_decoded. $iv = base64_decode(substr($encrypted, 0, 22) . '=='); // Remove $iv from $encrypted. $encrypted = substr($encrypted, 22); // Decrypt the data. rtrim won't corrupt the data because the last 32 characters are the md5 hash; thus any \0 character has to be padding. @$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv), "\0\4"); // Retrieve $hash which is the last 32 characters of $decrypted. $hash = substr($decrypted, - 32); // Remove the last 32 characters from $decrypted. $decrypted = substr($decrypted, 0, - 32); // Integrity check. If this fails, either the data is corrupted, or the password/salt was incorrect. if (md5($decrypted) != $hash) return false; // Yay! return $decrypted; } /** * 256-bit encryption with mcrypt * MCRYPT_RIJNDAEL_128 is AES-compliant, and MCRYPT_MODE_CBC * Note: ECB mode is inadequate for many purposes because it does not use an IV * * @param string $decrypted receives the unencrypted string to encrypt * return bool false on fail, or encrypted string if succeeded */ function myEncrypt($decrypted) { // salt $salt = '!kqM*Ff7pXe1kBn%9'; // Build a 256-bit $key which is a SHA256 hash of $salt and $password. $key = hash('SHA256', $salt ."LPC9aVs3w8k45vx7oHOxZgoNus3banTGPp5wmhJ6hSnJko9rjB/G5Q1mdhdxjm01q6kK2h44MP5L6DML4nY/uq", true); // Build $iv and $iv_base64. We use a block size of 128 bits (AES compliant) and CBC mode. (Note: ECB mode is inadequate as IV is not used.) srand(); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22) return false; // Encrypt $decrypted and an MD5 of $decrypted using $key. MD5 is fine to use here because it's just to verify successful decryption. $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $decrypted . md5($decrypted), MCRYPT_MODE_CBC, $iv)); // We're done! return $iv_base64 . $encrypted; }
プロジェクト ID: 6323804

プロジェクトについて

6個の提案
リモートプロジェクト
アクティブ 10年前

お金を稼ぎたいですか?

Freelancerで入札する利点

予算と期間を設定してください
仕事で報酬を得る
提案をご説明ください
登録して仕事に入札するのは無料です
アワード者:
ユーザーアバター
Hi, after reading your requirements i decided to place a bid on this project. I lead a team of node.js development. My total experience in node.js is around three years. overall IT experience is 7 years. We have experienced team of experts of Node.js, html designers, mongodb and web applications. We can discuss more on skype username 'morwal89'. Hope to hear back. Thank you.
$35 USD 1日以内
5.0 (1 レビュー)
1.8
1.8
この仕事に6人のフリーランサーが、平均$43 USDで入札しています
ユーザーアバター
一个有效的提议尚未被提供
$30 USD 1日以内
0.0 (0 レビュー)
0.0
0.0
ユーザーアバター
Hello, The task is trivial. I will create a node module (wrapper over crypto module) which exports two functions: encrypt and decrypt. I have a 4 years experience in designing complex software using python and nodejs. Thank you and good luck!
$30 USD 1日以内
0.0 (0 レビュー)
0.0
0.0
ユーザーアバター
I am a highly experienced developer and very familiar with javascript and node.js Your task is straight-forward and I will complete it very quickly with unit tests included.
$45 USD 1日以内
0.0 (0 レビュー)
0.0
0.0

クライアントについて

UNITED ARAB EMIRATESのフラグ
dxb, United Arab Emirates
5.0
1
お支払い方法確認済み
メンバー登録日:7月 15, 2014

クライアント確認

ありがとうございます!無料クレジットを受け取るリンクをメールしました。
メールを送信中に問題が発生しました。もう一度お試しください。
登録ユーザー 投稿された仕事の合計
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
プレビューを読み込み中
位置情報へのアクセスが許可されました。
あなたのログインセッションの有効期限がきれ、ログアウトされました。もう一度ログインしてください。