bool Cryptography::LoadKeyPair() { if (!QFile::exists("cryptography/wakbox.ppk")) return false; CryptoPP::FileSource privKeyFile("cryptography/wakbox.ppk", true); m_privateKey.Load(privKeyFile); QFile pubKeyFile("cryptography/wakbox.pub"); if (!pubKeyFile.open(QIODevice::ReadOnly)) return false; m_publicKey = pubKeyFile.readAll(); return true; }
bool Upload::sshKeyGen(){ //if not exists '~/.ssh/id_rsa.pub' then ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa QFile pubKeyFile(QDir::homePath() + "/.ssh/id_rsa.pub"); if(!pubKeyFile.exists()){ RunResult keygenRes = Runner::run("ssh-keygen -t rsa -N \"\" -f " + QDir::homePath() + "/.ssh/id_rsa"); if(keygenRes.status) { QMessageBox::critical (this, "Error", "ssh-keygen did not finish properly!"); //qDebug() << "ssh-keygen out:" << keygenRes.stdOut << keygenRes.stdErr; return false; } }else{ qDebug() << "Skipping keygen"; } return true; }
bool Cryptography::GenerateKeyPair() { QDir dir; dir.mkdir("cryptography"); CryptoPP::AutoSeededRandomPool prng; CryptoPP::InvertibleRSAFunction privateKey; privateKey.Initialize(prng, 1024); CryptoPP::RSAFunction publicKey(privateKey); CryptoPP::FileSink privKeyFile("cryptography/wakbox.ppk"); CryptoPP::FileSink pubKeyFile("cryptography/wakbox.pub"); privateKey.Save(privKeyFile); publicKey.Save(pubKeyFile); return LoadKeyPair(); }