Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function encryptPassword(arg1:String, arg2:String, arg3:String, arg4:uint=0, arg5:int=4096):void
- {
- var password:String;
- var salt:String;
- var challenge:String;
- var hashType:uint=0;
- var iterations:int=4096;
- var onComplete_PBKDF2:Function;
- var keyLen:int;
- var pbkdf2:sirius.crypto.s3mp.PBKDF2;
- var loc1:*;
- onComplete_PBKDF2 = null;
- pbkdf2 = null;
- password = arg1;
- salt = arg2;
- challenge = arg3;
- hashType = arg4;
- iterations = arg5;
- onComplete_PBKDF2 = function (arg1:flash.events.Event):void
- {
- pbkdf2.removeEventListener(flash.events.Event.COMPLETE, onComplete_PBKDF2);
- var loc1:*=sirius.crypto.Crypto.hashValue(hwid + ethernetMac + challenge);
- var loc2:*=challenge + loc1;
- passwordKey = com.hurlant.util.Hex.fromArray(pbkdf2.getResult());
- encryptedPassword = encryptRC4(loc2, passwordKey);
- dispatchEvent(new sirius.crypto.events.CryptoEvent(password, passwordKey, encryptedPassword));
- return;
- }
- var loc2:*=hashType;
- switch (loc2)
- {
- case 0:
- {
- password = sirius.crypto.Crypto.md5Hash(password);
- break;
- }
- case 1:
- {
- password = sirius.crypto.Crypto.md5Hash(password, true);
- break;
- }
- case 2:
- default:
- {
- password = DEFAULT_HASH;
- break;
- }
- }
- keyLen = 16;
- pbkdf2 = new sirius.crypto.s3mp.PBKDF2(new com.hurlant.crypto.hash.SHA256(), com.hurlant.util.Hex.toArray(password), com.hurlant.util.Hex.toArray(salt), keyLen);
- pbkdf2.addEventListener(flash.events.Event.COMPLETE, onComplete_PBKDF2);
- pbkdf2.calculate(iterations);
- return;
- }
- protected static const hwid:String="00000000";
- protected static const ethernetMac:String="0000CAFEBABE";
- protected static const AES_KEY:String="263223a3a6c0a0050936623771ee35c7db1794b2a6ad8c9321963c427b0b999c";
- protected static const DEFAULT_HASH:String="D0DB1CA3B300831A301AF9144FC6986A";
- public var passwordKey:String;
- public var encryptedPassword:String;
- // package s3mp
- // class PBKDF2
- package sirius.crypto.s3mp
- {
- import com.hurlant.crypto.hash.*;
- import flash.events.*;
- import flash.utils.*;
- import sirius.utils.*;
- public class PBKDF2 extends flash.events.EventDispatcher
- {
- public function PBKDF2(arg1:com.hurlant.crypto.hash.IHash, arg2:flash.utils.ByteArray, arg3:flash.utils.ByteArray, arg4:uint)
- {
- var loc1:*=0;
- super();
- this._hashSize = arg1.getHashSize();
- this._hmac = new com.hurlant.crypto.hash.HMAC(arg1, this._hashSize * 8);
- this._password = arg2;
- this._salt = arg3;
- this._currentIteration = 0;
- this._l = arg4 / this._hashSize;
- if (arg4 % this._hashSize != 0)
- {
- var loc2:*;
- var loc3:*=((loc2 = this)._l + 1);
- loc2._l = loc3;
- }
- this._r = arg4 - (this._l - 1) * this._hashSize;
- this.processThreader = new sirius.utils.ProcessThreader();
- return;
- }
- public function calculate(arg1:uint):void
- {
- var loc1:*=null;
- this.iterations = arg1;
- if (this._currentIteration == 0 && this.iterations > 0)
- {
- this._f = new Array();
- this._oldU = new Array();
- this.blockCounter = 0;
- while (this.blockCounter < this._l)
- {
- loc1 = new flash.utils.ByteArray();
- loc1.writeBytes(this._salt);
- loc1.writeUnsignedInt(this.blockCounter + 1);
- this._f[this.blockCounter] = this._hmac.compute(this._password, loc1);
- this._oldU[this.blockCounter] = new flash.utils.ByteArray();
- (this._oldU[this.blockCounter] as flash.utils.ByteArray).writeBytes(this._f[this.blockCounter]);
- var loc2:*;
- var loc3:*=((loc2 = this).blockCounter + 1);
- loc2.blockCounter = loc3;
- }
- loc3 = ((loc2 = this)._currentIteration + 1);
- loc2._currentIteration = loc3;
- loc3 = ((loc2 = this).iterations - 1);
- loc2.iterations = loc3;
- }
- this.processThreader.start(this.application_enterFrameHandler, this);
- return;
- }
- protected function application_enterFrameHandler(arg1:flash.events.Event):void
- {
- var loc2:*=0;
- var loc1:*=this.iterations - ITERATIONS_PER_FRAME > 0 ? ITERATIONS_PER_FRAME : this.iterations;
- if (loc1 > 0)
- {
- loc2 = 0;
- while (loc2 < loc1)
- {
- this.u = new Array();
- this.blockCounter = 0;
- while (this.blockCounter < this._l)
- {
- this.u[this.blockCounter] = this._hmac.compute(this._password, this._oldU[this.blockCounter]);
- this.byteCounter = this._hashSize;
- do
- {
- var loc3:*;
- var loc4:*=((loc3 = this).byteCounter - 1);
- loc3.byteCounter = loc4;
- this._f[this.blockCounter][this.byteCounter] = this._f[this.blockCounter][this.byteCounter] ^ this.u[this.blockCounter][this.byteCounter];
- }
- while (this.byteCounter > 0);
- loc4 = ((loc3 = this).blockCounter + 1);
- loc3.blockCounter = loc4;
- }
- loc4 = ((loc3 = this)._currentIteration + 1);
- loc3._currentIteration = loc4;
- this._oldU = this.u;
- loc4 = ((loc3 = this).iterations - 1);
- loc3.iterations = loc4;
- if (this.iterations != 0)
- {
- };
- ++loc2;
- }
- }
- if (this.iterations == 0)
- {
- this.processThreader.stop();
- dispatchEvent(new flash.events.Event(flash.events.Event.COMPLETE));
- }
- return;
- }
- public function getResult():flash.utils.ByteArray
- {
- var loc1:*=0;
- var loc2:*=new flash.utils.ByteArray();
- if (this._l > 0)
- {
- loc1 = 0;
- while (loc1 < (this._l - 1))
- {
- loc2.writeBytes(this._f[loc1]);
- ++loc1;
- }
- loc2.writeBytes(this._f[(this._l - 1)], 0, this._r);
- }
- return loc2;
- }
- {
- ITERATIONS_PER_FRAME = 35;
- }
- internal var _hashSize:uint;
- internal var _hmac:com.hurlant.crypto.hash.HMAC;
- internal var _l:uint;
- internal var _r:uint;
- internal var _password:flash.utils.ByteArray;
- internal var _salt:flash.utils.ByteArray;
- internal var _oldU:Array;
- internal var _f:Array;
- internal var _currentIteration:uint;
- protected var iterations:uint;
- protected var blockCounter:uint;
- protected var byteCounter:uint;
- protected var u:Array;
- protected var processThreader:sirius.utils.ProcessThreader;
- protected static var ITERATIONS_PER_FRAME:int=35;
- }
- }
- // class Crypto
- package sirius.crypto
- {
- import com.adobe.crypto.*;
- import com.hurlant.crypto.*;
- import com.hurlant.crypto.hash.*;
- import com.hurlant.crypto.symmetric.*;
- import com.hurlant.util.*;
- import flash.events.*;
- import flash.utils.*;
- import sirius.crypto.events.*;
- import sirius.crypto.s3mp.*;
- import sirius.utils.string.*;
- public class Crypto extends flash.events.EventDispatcher
- {
- public function Crypto()
- {
- super();
- return;
- }
- public function encryptPassword(arg1:String, arg2:String, arg3:String, arg4:uint=0, arg5:int=4096):void
- {
- var password:String;
- var salt:String;
- var challenge:String;
- var hashType:uint=0;
- var iterations:int=4096;
- var onComplete_PBKDF2:Function;
- var keyLen:int;
- var pbkdf2:sirius.crypto.s3mp.PBKDF2;
- var loc1:*;
- onComplete_PBKDF2 = null;
- pbkdf2 = null;
- password = arg1;
- salt = arg2;
- challenge = arg3;
- hashType = arg4;
- iterations = arg5;
- onComplete_PBKDF2 = function (arg1:flash.events.Event):void
- {
- pbkdf2.removeEventListener(flash.events.Event.COMPLETE, onComplete_PBKDF2);
- var loc1:*=sirius.crypto.Crypto.hashValue(hwid + ethernetMac + challenge);
- var loc2:*=challenge + loc1;
- passwordKey = com.hurlant.util.Hex.fromArray(pbkdf2.getResult());
- encryptedPassword = encryptRC4(loc2, passwordKey);
- dispatchEvent(new sirius.crypto.events.CryptoEvent(password, passwordKey, encryptedPassword));
- return;
- }
- var loc2:*=hashType;
- switch (loc2)
- {
- case 0:
- {
- password = sirius.crypto.Crypto.md5Hash(password);
- break;
- }
- case 1:
- {
- password = sirius.crypto.Crypto.md5Hash(password, true);
- break;
- }
- case 2:
- default:
- {
- password = DEFAULT_HASH;
- break;
- }
- }
- keyLen = 16;
- pbkdf2 = new sirius.crypto.s3mp.PBKDF2(new com.hurlant.crypto.hash.SHA256(), com.hurlant.util.Hex.toArray(password), com.hurlant.util.Hex.toArray(salt), keyLen);
- pbkdf2.addEventListener(flash.events.Event.COMPLETE, onComplete_PBKDF2);
- pbkdf2.calculate(iterations);
- return;
- }
- public function decryptRC4(arg1:String, arg2:String):String
- {
- var text:String;
- var key:String;
- var dst:flash.utils.ByteArray;
- var loc1:*;
- text = arg1;
- key = arg2;
- dst = new flash.utils.ByteArray();
- dst.writeBytes(com.hurlant.util.Hex.toArray(text));
- try
- {
- this.buildKeyCipher(key).decrypt(dst);
- }
- catch (e:Error)
- {
- return "";
- }
- return com.hurlant.util.Hex.fromArray(dst);
- }
- public function encryptRC4(arg1:String, arg2:String):String
- {
- var text:String;
- var key:String;
- var dst:flash.utils.ByteArray;
- var loc1:*;
- text = arg1;
- key = arg2;
- dst = new flash.utils.ByteArray();
- dst.writeBytes(com.hurlant.util.Hex.toArray(text));
- try
- {
- this.buildKeyCipher(key).encrypt(dst);
- }
- catch (e:Error)
- {
- return "";
- }
- return com.hurlant.util.Hex.fromArray(dst);
- }
- protected function buildKeyCipher(arg1:String):com.hurlant.crypto.symmetric.CBCMode
- {
- var loc1:*=new flash.utils.ByteArray();
- loc1[15] = 0;
- var loc2:*=new com.hurlant.crypto.symmetric.CBCMode(new com.hurlant.crypto.symmetric.AESKey(com.hurlant.util.Hex.toArray(arg1)));
- loc2.IV = loc1;
- return loc2;
- }
- public static function hashValue(arg1:String, arg2:int=16):String
- {
- var loc1:*=com.hurlant.util.Hex.toArray(arg1);
- var loc2:*=new com.hurlant.crypto.hash.SHA256().hash(loc1);
- return com.hurlant.util.Hex.fromArray(loc2).substr(0, arg2 * 2);
- }
- public static function md5Hash(arg1:String, arg2:Boolean=false):String
- {
- arg1 = arg1 || "";
- if (arg2)
- {
- arg1 = arg1.toUpperCase();
- }
- return com.adobe.crypto.MD5.hash(sirius.utils.string.trim(arg1));
- }
- public static function protect(arg1:String):String
- {
- var loc1:*=com.hurlant.util.Hex.toArray(com.hurlant.util.Hex.fromString(arg1));
- buildCipher().encrypt(loc1);
- return com.hurlant.util.Hex.fromArray(loc1);
- }
- public static function unprotect(arg1:String):String
- {
- var loc1:*=com.hurlant.util.Hex.toArray(arg1);
- buildCipher().decrypt(loc1);
- return com.hurlant.util.Hex.toString(com.hurlant.util.Hex.fromArray(loc1));
- }
- protected static function buildCipher():com.hurlant.crypto.symmetric.ICipher
- {
- var loc1:*=new com.hurlant.crypto.symmetric.PKCS5();
- var loc2:*=com.hurlant.crypto.Crypto.getCipher("rc4-cbc", com.hurlant.util.Hex.toArray(AES_KEY), loc1);
- loc1.setBlockSize(loc2.getBlockSize());
- return loc2;
- }
- protected static const hwid:String="00000000";
- protected static const ethernetMac:String="0000CAFEBABE";
- protected static const AES_KEY:String="263223a3a6c0a0050936623771ee35c7db1794b2a6ad8c9321963c427b0b999c";
- protected static const DEFAULT_HASH:String="D0DB1CA3B300831A301AF9144FC6986A";
- public var passwordKey:String;
- public var encryptedPassword:String;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment