2015-04-02 20:32:22 +00:00
|
|
|
var OFFCRYPTO = {};
|
2017-03-12 18:02:43 +00:00
|
|
|
|
2015-04-02 20:32:22 +00:00
|
|
|
var make_offcrypto = function(O, _crypto) {
|
|
|
|
var crypto;
|
|
|
|
if(typeof _crypto !== 'undefined') crypto = _crypto;
|
|
|
|
else if(typeof require !== 'undefined') {
|
2017-03-05 00:56:31 +00:00
|
|
|
try { crypto = require('crypto'); }
|
2015-04-02 20:32:22 +00:00
|
|
|
catch(e) { crypto = null; }
|
|
|
|
}
|
|
|
|
|
|
|
|
O.rc4 = function(key, data) {
|
|
|
|
var S = new Array(256);
|
|
|
|
var c = 0, i = 0, j = 0, t = 0;
|
|
|
|
for(i = 0; i != 256; ++i) S[i] = i;
|
|
|
|
for(i = 0; i != 256; ++i) {
|
|
|
|
j = (j + S[i] + (key[i%key.length]).charCodeAt(0))&255;
|
|
|
|
t = S[i]; S[i] = S[j]; S[j] = t;
|
|
|
|
}
|
2017-03-12 18:02:43 +00:00
|
|
|
// $FlowIgnore
|
|
|
|
i = j = 0; var out = Buffer(data.length);
|
2015-04-02 20:32:22 +00:00
|
|
|
for(c = 0; c != data.length; ++c) {
|
|
|
|
i = (i + 1)&255;
|
|
|
|
j = (j + S[i])%256;
|
|
|
|
t = S[i]; S[i] = S[j]; S[j] = t;
|
|
|
|
out[c] = (data[c] ^ S[(S[i]+S[j])&255]);
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
O.md5 = function(hex) {
|
|
|
|
if(!crypto) throw new Error("Unsupported crypto");
|
|
|
|
return crypto.createHash('md5').update(hex).digest('hex');
|
|
|
|
};
|
2015-04-02 20:32:22 +00:00
|
|
|
};
|
2017-03-12 18:02:43 +00:00
|
|
|
/*:: declare var crypto:any; */
|
2017-05-09 18:07:57 +00:00
|
|
|
/*global crypto:true */
|
2015-04-02 20:32:22 +00:00
|
|
|
make_offcrypto(OFFCRYPTO, typeof crypto !== "undefined" ? crypto : undefined);
|
|
|
|
|