void FileSignatureWorker::process() { if(m_manifest) { float prev_percentage=-1.0f; int current_idx=0; int count = m_manifest->m_files.size(); for(auto &fileentry : m_manifest->m_files) { QCryptographicHash crypto(QCryptographicHash::Sha1); QFile file(fileentry.m_relativePath); current_idx++; if(!file.open(QFile::ReadOnly)) { emit error(tr("Failed to open file %1").arg(fileentry.m_relativePath)); continue; } while(!file.atEnd()){ crypto.addData(file.read(8192)); } QByteArray hash = crypto.result(); fileentry.m_signature = hash.toHex(); float current_percentage = 100.0f * float(current_idx)/count; if(prev_percentage+1<=current_percentage) { emit progress(m_manifest->m_version,current_percentage); prev_percentage = current_percentage; } } } emit progress(m_manifest->m_version,100.0); emit finished(); }
int main(int argc, char *argv[]) { int log=0; log=crypto(); if(log==1 || log==2){ umask(0); xmp_state state; if(argc < 4){ fprintf(stderr, "Input Pattern: ./menfuser \n"); return 1; } state.rootdir = realpath(argv[2], NULL); strncpy(state.key, argv[1], 32); state.key[31] = '\0'; printf("Filesystem Mounted!!"); return fuse_main(argc - 2, argv + 2, &xmp_oper, &state); } else if(log==0 || log==999){printf("Access Restricted\n"); }return 0; }
static int crypto( const char *key, bool decrypt, const bytes_t &bytes, bytes_t &crypt ) { CRYPTO_malloc_debug_init(); CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); RAND_seed(rnd_seed, sizeof(rnd_seed)); /* or OAEP may fail */ RSA *rsa = NULL; int rval = loadKey(key, decrypt, &rsa); if ( rval == 0 ) rval = crypto(rsa, decrypt, bytes, crypt); RSA_free(rsa); ERR_print_errors_fp(stdout); CRYPTO_cleanup_all_ex_data(); EVP_cleanup(); ERR_remove_state(0); CRYPTO_mem_leaks_fp(stderr); return ( rval ); }
/** * Compute the SHA1 hash for the given file. * @param filename The filename (with or without prefixed by a path). If the file * is not found the exeption 'FileNotFoundException' is thrown. * @param bufferSize The size of the buffer used to give the data to 'QCryptographicHash'. * @return The sha1 hash. */ QByteArray computeSHA1(const QString& filename, qint32 bufferSize) throw (FileNotFoundException) { #if not WITH_SHA1_LINUS QCryptographicHash crypto(QCryptographicHash::Sha1); #endif QFile file(filename); if (!file.open(QIODevice::ReadOnly)) throw FileNotFoundException(); #if WITH_SHA1_LINUS blk_SHA_CTX sha1State; blk_SHA1_Init(&sha1State); unsigned char bufferHash[20]; #endif char buffer[bufferSize]; qint64 bytesRead = 0; while ((bytesRead = file.read(buffer, bufferSize)) > 0) { #if WITH_SHA1_LINUS blk_SHA1_Update(&sha1State, buffer, bytesRead); #else crypto.addData(buffer, bytesRead); #endif } #if WITH_SHA1_LINUS blk_SHA1_Final(bufferHash, &sha1State); return QByteArray((const char*)bufferHash, 20); #else return crypto.result(); #endif }
extern "C" int main( int argc, const char **argv ) { if ( argc < 2 ) return ( usage(argv[0]) ); WINDOWS_STD_INOUT_BINARY int rval = 0; bool decrypt = testFlag(argc, argv, 'd'); bytes_t bytes; rval = fileToBytes(stdin, bytes); if ( rval != 0 ) return ( rval ); bytes_t crypt; rval = crypto(argv[argc-1], decrypt, bytes, crypt); fprintf(stderr, "crypto returned: %d\n", rval); if ( rval == 0 ) fwrite(&crypt[0], sizeof(bytes_t::value_type), crypt.size(), stdout); return ( 0 ); }
SPL::blob aesencrypt(const SPL::blob &key, const SPL::blob& input_data) { int outputLen = 0; const int len = input_data.getSize(); unsigned char output[len + BYTES_PER_BLOCK]; crypto(key.getData(),input_data.getData(),input_data.getSize(),&(output[0]),&outputLen,true); SPL::blob myblob(output,outputLen);; return myblob; }
SPL::blob aesdecrypt(const SPL::blob& key, const SPL::blob &input_data) { int outputLen = 0; const int len = input_data.getSize(); // allocate a little extra space unsigned char output[len+BYTES_PER_BLOCK]; crypto(key.getData(),input_data.getData(),input_data.getSize(),&(output[0]), &outputLen,false); SPL::blob myblob(output,outputLen); return myblob; }
void Settings::setAuthUrl(const QString &value) { SimpleCrypt crypto(KEY); QString encryptedValue = crypto.encryptToString(value); if (!crypto.lastError() == SimpleCrypt::ErrorNoError) { emit error(512); } settings.setValue("authurl", encryptedValue); }
void Settings::setTwitterCookie(const QString &value) { SimpleCrypt crypto(KEY); QString encryptedValue = crypto.encryptToString(value); if (!crypto.lastError() == SimpleCrypt::ErrorNoError) { emit error(512); } settings.setValue("twittercookie", encryptedValue); }
void Settings::setPassword(const QString &value) { SimpleCrypt crypto(KEY); QString encryptedPassword = crypto.encryptToString(value); if (!crypto.lastError() == SimpleCrypt::ErrorNoError) { emit error(512); } settings.setValue("password", encryptedPassword); }
int main(int argc, char **argv) { int ch; char keyfile[128]; int as_daemon = 0; bzero(keyfile, sizeof(keyfile)); while(-1 != (ch=getopt(argc, argv, "dhk:"))) { switch(ch) { case 'k': strncpy(keyfile, optarg, sizeof(keyfile)-1); break; case 'd': as_daemon = 1; break; case 'h': default: print_help(argv[0]); exit(0); break; } } /* // If the user didn't specify a keyfile, print out help and exit. if(!keyfile[0]) { print_help(argv[0]); exit(0); } */ argc -= optind; argv += optind; if(as_daemon) if(daemon(1, 0)) perror("Unable to run as daemon"); // Have signals call our cleanup function. // We do this first since creating pidfiles and pipes can block. signal(SIGTERM, cleanup); signal(SIGPIPE, SIG_IGN); signal(SIGHUP, cleanup); signal(SIGINT, cleanup); while (1) crypto(keyfile); cleanup(0); }
void CDVDVideoCodecAndroidMediaCodec::ConfigureMediaCodec(void) { // setup a MediaFormat to match the video content, // used by codec during configure CJNIMediaFormat mediaformat = CJNIMediaFormat::createVideoFormat( m_mime.c_str(), m_hints.width, m_hints.height); // some android devices forget to default the demux input max size mediaformat.setInteger(CJNIMediaFormat::KEY_MAX_INPUT_SIZE, 0); // handle codec extradata if (m_hints.extrasize) { size_t size = m_hints.extrasize; void *src_ptr = m_hints.extradata; if (m_bitstream) { size = m_bitstream->GetExtraSize(); src_ptr = m_bitstream->GetExtraData(); } // Allocate a byte buffer via allocateDirect in java instead of NewDirectByteBuffer, // since the latter doesn't allocate storage of its own, and we don't know how long // the codec uses the buffer. CJNIByteBuffer bytebuffer = CJNIByteBuffer::allocateDirect(size); void *dts_ptr = xbmc_jnienv()->GetDirectBufferAddress(bytebuffer.get_raw()); memcpy(dts_ptr, src_ptr, size); // codec will automatically handle buffers as extradata // using entries with keys "csd-0", "csd-1", etc. mediaformat.setByteBuffer("csd-0", bytebuffer); } InitSurfaceTexture(); // configure and start the codec. // use the MediaFormat that we have setup. // use a null MediaCrypto, our content is not encrypted. // use a null Surface, we will extract the video picture data manually. int flags = 0; CJNIMediaCrypto crypto(jni::jhobject(NULL)); // our jni gets upset if we do this a different // way, do not mess with it. if (m_render_sw) { CJNISurface surface(jni::jhobject(NULL)); m_codec->configure(mediaformat, surface, crypto, flags); } else { m_codec->configure(mediaformat, *m_surface, crypto, flags); } m_codec->start(); // always, check/clear jni exceptions. if (xbmc_jnienv()->ExceptionOccurred()) xbmc_jnienv()->ExceptionClear(); }
QString Settings::getAuthUrl() { SimpleCrypt crypto(KEY); QString plainValue = crypto.decryptToString(settings.value("authurl", "").toString()); if (!crypto.lastError() == SimpleCrypt::ErrorNoError) { emit error(511); return ""; } return plainValue; }
QString Settings::getPassword() { SimpleCrypt crypto(KEY); QString plainPassword = crypto.decryptToString(settings.value("password", "").toString()); if (!crypto.lastError() == SimpleCrypt::ErrorNoError) { emit error(511); return ""; } return plainPassword; }
QString Settings::getTwitterCookie() { SimpleCrypt crypto(KEY); QString plainValue = crypto.decryptToString(settings.value("twittercookie", "").toString()); if (!crypto.lastError() == SimpleCrypt::ErrorNoError) { emit error(511); return ""; } return plainValue; }
String FileHandler::computeFileHash_(const String& filename) const { QCryptographicHash crypto(QCryptographicHash::Sha1); QFile file(filename.toQString()); file.open(QFile::ReadOnly); while (!file.atEnd()) { crypto.addData(file.read(8192)); } return String((QString)crypto.result().toHex()); }
QPair<QString, QString> cm_md5_map(const QString &file) { QCryptographicHash crypto(QCryptographicHash::Md5); QFile f(file); f.open(QFile::ReadOnly); while (!f.atEnd()){ crypto.addData(f.read(4*1024)); // 4k read } // qDebug() << __func__ << QString(crypto.result().toHex()) << "file:" << file; return qMakePair(file, QString(crypto.result().toHex())); }
/** * Compute some SHA1 hash for each chunk of the given file. * @param filename The filename (with or without prefixed by a path). If the file * is not found the exeption 'FileNotFoundException' is thrown. * @param chunkSize The size of each chunk. It must be a divisor of 'bufferSizer'. * @param bufferSize The size of the buffer used to give the data to 'QCryptographicHash'. * @return A list of chunk hashes. */ QList<QByteArray> computeMultiSHA1(const QString& filename, qint32 chunkSize, qint32 bufferSize) throw (FileNotFoundException) { QList<QByteArray> result; #if not WITH_SHA1_LINUS QCryptographicHash crypto(QCryptographicHash::Sha1); #endif QFile file(filename); if (!file.open(QIODevice::ReadOnly)) throw FileNotFoundException(); #if WITH_SHA1_LINUS blk_SHA_CTX sha1State; unsigned char bufferHash[20]; #endif char buffer[bufferSize]; bool endOfFile = false; while (!endOfFile) { #if WITH_SHA1_LINUS blk_SHA1_Init(&sha1State); #endif qint64 bytesReadTotal = 0; while (bytesReadTotal < chunkSize) { qint64 bytesRead = file.read(buffer, bufferSize); if (bytesRead == 0) { endOfFile = true; break; } #if WITH_SHA1_LINUS blk_SHA1_Update(&sha1State, buffer, bytesRead); #else crypto.addData(buffer, bytesRead); #endif bytesReadTotal += bytesRead; } #if WITH_SHA1_LINUS blk_SHA1_Final(bufferHash, &sha1State); result.append(QByteArray((const char*)bufferHash, 20)); #else result.append(crypto.result()); crypto.reset(); #endif } return result; }
static QByteArray readToCrypto( const QString& filename, QCryptographicHash::Algorithm algo ) { QFile file(filename); QByteArray arr; QCryptographicHash crypto( algo ); if (file.open(QIODevice::ReadOnly)) { if (crypto.addData(&file)) { arr = crypto.result().toHex(); } } return arr; }
QString checkMd5(QString file_path){ // Generate hash of original file QFile file(file_path); QCryptographicHash crypto(QCryptographicHash::Md5); file.open(QFile::ReadOnly); while(!file.atEnd()){ crypto.addData(file.read(8192)); } QByteArray hash = crypto.result().toHex(); QString hash_string = hash; file.close(); return hash_string; }
QByteArray Global::sha1CheckSum(const QString filePath) { QCryptographicHash crypto(QCryptographicHash::Sha1); QFile file(filePath); if (!file.open(QFile::ReadOnly)) return QByteArray(); while(!file.atEnd()){ crypto.addData(file.read(8192)); } return crypto.result(); }
int main(int argc, char* argv[]) { unsigned long dwResult = 0; unsigned char plainText[BUFFERLENGTH]; unsigned char cipher[BUFFERLENGTH]; unsigned char random[17]; unsigned char encryptrandom[33]; // clear text memset(plainText, 0, BUFFERLENGTH); memcpy(plainText, "select * from t0a12 where", BUFFERLENGTH); // test encrypt printf("Begin encrypt in TDES_ECB mode...\n"); memset(cipher, 0, BUFFERLENGTH); crypto(0, plainText, cipher); printf("Success!\nThe cipher:"); hexprint(stdout, cipher, BUFFERLENGTH); // test decrypt printf("Begin decrypt in TDES_ECB mode...\n"); memset(plainText, 0, BUFFERLENGTH); crypto(1, cipher, plainText); printf("Success!\nThe plainText:"); hexprint(stdout, plainText, BUFFERLENGTH); printf("%s",plainText); // test encryptrand memset(random, 0, 17); memset(encryptrandom, 0, 33); memcpy(random, "FCVK3MP6B0d8TezE", 16); encryptrand(random, encryptrandom); hexprint(stdout, random, 16); printf("\n%s\n", encryptrandom); return dwResult; }
void Sudoku::cargarPartida(){ SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f023)); QFile archivo(":/recursos/partida.txt"); if (archivo.exists(":/recursos/partida.txt")){ archivo.open(QFile::ReadOnly); QTextStream stream(&archivo); QString crypt=stream.readAll(); QString linea=crypto.decryptToString(crypt); pasarStringAMatriz(linea); pasarMatrizAUI(); } else { QMessageBox::critical(this,"Error","No existe el archivo "); } archivo.close(); }
bool Myth::ChangePassword( const QString &sUserName, const QString &sOldPassword, const QString &sNewPassword ) { bool bResult = false; if (sUserName.isEmpty()) { throw ( QString( "UserName not supplied when trying to change " "password." ) ); } if (sOldPassword.isEmpty()) { throw ( QString( "Old Password not supplied when trying to change " "password for '%1'." ).arg(sUserName) ); } if (sNewPassword.isEmpty()) { throw ( QString( "New Password not supplied when trying to change " "password for '%1'." ).arg(sUserName) ); } QCryptographicHash crypto( QCryptographicHash::Sha1 ); crypto.addData( sOldPassword.toUtf8() ); QString sPasswordHash( crypto.result().toBase64() ); if ( sPasswordHash != gCoreContext->GetSetting( "HTTP/Protected/Password", "")) { throw ( QString( "Incorrect Old Password supplied when trying to " "change password for '%1'." ).arg(sUserName) ); } crypto.reset(); crypto.addData( sNewPassword.toUtf8() ); if (gCoreContext->SaveSettingOnHost( "HTTP/Protected/Password", crypto.result().toBase64(), QString() ) ) { gCoreContext->ClearSettingsCache(); bResult = true; } return bResult; }
QPair<QString, QString> cm_imageData_map(const QString &file) { QCryptographicHash crypto(); QImage img(file); if (img.isNull()) { // Not an image, return empty pair return qMakePair(QString(), QString()); } QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); img.save(&buffer, "PNG"); // writes image into ba in PNG format return qMakePair(file, QString(QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex())); }
QString CaViewerScanner::getMd5Hash(QString sFullName) { QFile file(sFullName); if(file.open(QFile::ReadOnly)) { QCryptographicHash crypto(QCryptographicHash::Md5); while(!file.atEnd()) crypto.addData(file.read(8192)); file.close(); return crypto.result().toHex(); } else return QString(); }
void CommunObject::decrypt(const QString &key, const QString &info) { qDebug() << "Key: " << key; qDebug() << "info: " << info; try { CryptoWrapper crypto(key, info); QString results; crypto.decrypt(results); emit sendResults(results); emit sendStatus("completed the Decryption operations"); qDebug() << "Results: " << results; } catch (...) { const QString message = "Error occurred while Decrypting"; emit sendStatus(message); qWarning() << message; } }
QString ignsystem::hashFile(const QString &path, QString hash_algo) { bool isValid = true; QCryptographicHash::Algorithm algo; if (hash_algo == QLatin1String("md4")) { algo = QCryptographicHash::Md4; } else if (hash_algo == QLatin1String("md5")) { algo = QCryptographicHash::Md5; } else if (hash_algo == QLatin1String("sha1")) { algo = QCryptographicHash::Sha1; } else if (hash_algo == QLatin1String("sha224")) { algo = QCryptographicHash::Sha224; } else if (hash_algo == QLatin1String("sha256")) { algo = QCryptographicHash::Sha256; } else if (hash_algo == QLatin1String("sha384")) { algo = QCryptographicHash::Sha384; } else if (hash_algo == QLatin1String("sha512")) { algo = QCryptographicHash::Sha512; } else if (hash_algo == QLatin1String("sha3-224")) { algo = QCryptographicHash::Sha3_224; } else if (hash_algo == QLatin1String("sha3-256")) { algo = QCryptographicHash::Sha3_256; } else if (hash_algo == QLatin1String("sha3-384")) { algo = QCryptographicHash::Sha3_384; } else if (hash_algo == QLatin1String("sha3-512")) { algo = QCryptographicHash::Sha3_512; } else { isValid = false; } if (isValid && QFile::exists(path) && QFileInfo(path).isFile()) { QCryptographicHash crypto(algo); QFile file(path); file.open(QFile::ReadOnly); while (!file.atEnd()) { crypto.addData(file.read(512)); } file.close(); QByteArray hash = crypto.result(); return hash.toHex(); } else { return NULL; } }
QString Settings::bugzillaPassword() { // I know this is not really secure, but how would one hide the // encryption key in OSS software? :P // At least it's not in the config file in cleartext... QSettings settings( "/etc/kueued.conf", QSettings::NativeFormat); SimpleCrypt crypto( Q_UINT64_C( 0424632454124622 ) ); QString pw; if ( !settings.value( "bugzillaPassword" ).toString().isEmpty() ) { pw = crypto.decryptToString( settings.value( "bugzillaPassword" ).toString() ); } return pw; }
void Sudoku::on_actionGuardar_partida_triggered() { SimpleCrypt crypto(Q_UINT64_C(0x0c2ad4a4acb9f023)); if (QMessageBox::Yes == QMessageBox::question(this, "Guardar", "¿Desea guardar la partida actual?", QMessageBox::Yes|QMessageBox::No)){ pasarUIAMatriz(); QString linea=pasarMatrizAString(); QString crypted=crypto.encryptToString(linea); QFile archivo(":/recursos/partida.txt"); if ( !archivo.open(QIODevice::WriteOnly)) { QMessageBox::critical(this,"Error!","La partida no se pudo guardar"); } else { QTextStream stream(&archivo); stream << crypted; stream.flush(); QMessageBox::information(this,"Guardado!","La partida se ha guardado con éxito"); } } }