stuff
This commit is contained in:
52
buildfiles/app/node_modules/nodeezcryptor/native/decryptor.cc
generated
vendored
Normal file
52
buildfiles/app/node_modules/nodeezcryptor/native/decryptor.cc
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
#include <napi.h>
|
||||
#include <iostream>
|
||||
#include "decryptor.h"
|
||||
|
||||
Napi::Value napiGetKey(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
std::string trackIdArg = info[0].As<Napi::String>().Utf8Value();
|
||||
char* trackId = new char[trackIdArg.length() + 1];
|
||||
strcpy(trackId, trackIdArg.c_str());
|
||||
|
||||
char key[16];
|
||||
getKey(trackId, key);
|
||||
return Napi::String::New(env, key, 16);
|
||||
}
|
||||
|
||||
void napiDecryptFile(const Napi::CallbackInfo& info) {
|
||||
std::string decKeyArg = info[0].As<Napi::String>().Utf8Value();
|
||||
char* decKey = new char[17];
|
||||
strcpy(decKey, decKeyArg.c_str());
|
||||
|
||||
std::string inputFn = info[1].As<Napi::String>().Utf8Value();
|
||||
std::string outputFn = info[2].As<Napi::String>().Utf8Value();
|
||||
decryptFile(decKey, inputFn.c_str(), outputFn.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Napi::Value napiDecryptBuffer(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
std::string decKeyArg = info[0].As<Napi::String>().Utf8Value();
|
||||
char* decKey = new char[17];
|
||||
strcpy(decKey, decKeyArg.c_str());
|
||||
size_t arrlen = info[1].As<Napi::Buffer<unsigned char>>().Length();
|
||||
unsigned char* buffer = info[1].As<Napi::Buffer<unsigned char>>().Data();
|
||||
|
||||
unsigned char* decrypted = new unsigned char[arrlen];
|
||||
decryptBytes(decKey, arrlen, buffer, decrypted);
|
||||
|
||||
return Napi::Buffer<unsigned char>::New(env, decrypted, arrlen);
|
||||
}
|
||||
|
||||
|
||||
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
exports.Set(Napi::String::New(env, "getKey"), Napi::Function::New(env, napiGetKey));
|
||||
exports.Set(Napi::String::New(env, "decryptFile"), Napi::Function::New(env, napiDecryptFile));
|
||||
exports.Set(Napi::String::New(env, "decryptBuffer"), Napi::Function::New(env, napiDecryptBuffer));
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_API_MODULE(decryptor, Init)
|
73
buildfiles/app/node_modules/nodeezcryptor/native/decryptor.h
generated
vendored
Normal file
73
buildfiles/app/node_modules/nodeezcryptor/native/decryptor.h
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/blowfish.h>
|
||||
|
||||
void getKey(char* trackId, char* key) {
|
||||
unsigned char digest[MD5_DIGEST_LENGTH];
|
||||
MD5_CTX context;
|
||||
MD5_Init(&context);
|
||||
MD5_Update(&context, trackId, strlen(trackId));
|
||||
MD5_Final(digest, &context);
|
||||
|
||||
char MD5String[33];
|
||||
for (int i = 0; i < 16; i++)
|
||||
sprintf(&MD5String[i*2], "%02x", (unsigned int)digest[i]);
|
||||
|
||||
const char secret[] = "g4el58wc0zvf9na1";
|
||||
|
||||
for(int i=0; i<16; i++)
|
||||
key[i] = MD5String[i] ^ MD5String[i+16] ^ secret[i];
|
||||
}
|
||||
|
||||
void decryptFile(char* decKey, const char* inputfn, const char* outputfn) {
|
||||
unsigned char* bfKey = reinterpret_cast<unsigned char*>(decKey);
|
||||
BF_KEY key;
|
||||
BF_set_key(&key, 16, bfKey);
|
||||
|
||||
FILE* ofile = fopen(outputfn, "wb");
|
||||
FILE* ifile = fopen(inputfn, "rb");
|
||||
|
||||
int i=0;
|
||||
while (!feof(ifile)) {
|
||||
unsigned char buffer[2048];
|
||||
int read = fread(buffer, 1, 2048, ifile);
|
||||
if (i % 3 == 0 && read == 2048) {
|
||||
unsigned char decrypted[2048];
|
||||
unsigned char IV[8] = {0,1,2,3,4,5,6,7};
|
||||
BF_cbc_encrypt(buffer, decrypted, 2048, &key, IV, BF_DECRYPT);
|
||||
fwrite(decrypted, sizeof(unsigned char), sizeof(decrypted), ofile);
|
||||
} else {
|
||||
fwrite(buffer, sizeof(unsigned char), read, ofile);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
fclose(ofile);
|
||||
fclose(ifile);
|
||||
}
|
||||
|
||||
void decryptBytes(char* decKey, long length, unsigned char* data, unsigned char* output) {
|
||||
unsigned char* bfKey = reinterpret_cast<unsigned char*>(decKey);
|
||||
BF_KEY key;
|
||||
BF_set_key(&key, 16, bfKey);
|
||||
int count = length/2048;
|
||||
|
||||
int i=0;
|
||||
for(i=0; i<count; i++) {
|
||||
if (i % 3 == 0) {
|
||||
unsigned char buffer[2048];
|
||||
memcpy(buffer, &data[i*2048], 2048);
|
||||
|
||||
unsigned char decrypted[2048];
|
||||
unsigned char IV[8] = {0,1,2,3,4,5,6,7};
|
||||
BF_cbc_encrypt(buffer, decrypted, 2048, &key, IV, BF_DECRYPT);
|
||||
memcpy(&output[i*2048], decrypted, 2048);
|
||||
} else {
|
||||
memcpy(&output[i*2048], &data[i*2048], 2048);
|
||||
}
|
||||
}
|
||||
if (length % 2048 != 0){
|
||||
memcpy(&output[i*2048], &data[i*2048], (length-(i*2048)));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user