Hi i've been trying to decrypt an onion adrress from a private key but I
can't seem to get it to work.
Here is the code I use.
I'm trying to apply this
U=$(openssl rsa -in a.pem -pubout -outform DER | tail -c +23 | shasum |
head -c 20 | python -c "import base64,sys; print
base64.b32encode(sys.stdin.readline().strip('\n').decode('hex')).lower()")
echo "http://${U}.onion:8080"
CryptoPP::RSA::PrivateKey priv_key_from_str(std::string key)
{
using namespace CryptoPP;
namespace po = boost::program_options;
string decoded;
StringSource ss(key, true,
new Base64Decoder(
new StringSink(decoded)
) // Base64Decoder
); // StringSource
StringSource stringSource( decoded, true);
CryptoPP::RSA::PrivateKey pk;
ByteQueue q;
stringSource.TransferTo(q);
bool ok;
pk.BERDecodePrivateKey(q,false,0);
CryptoPP::AutoSeededRandomPool prng;
ok=pk.Validate(prng, 3);
//DumpPrivateKey(pk);
return pk;
}
int main(int argc, char** argv) {
using namespace CryptoPP;
//DumpPrivateKey(priv_key_from_str(key));
CryptoPP::RSA::PrivateKey privk=priv_key_from_str(key); //key is a string
stripped from the onion privatekey. It decrypts and verifys fine
RSAFunction pubkey(privk);
DumpPublicKey(pubkey);
CryptoPP::SHA1 sha1;
std::string hash_sha1;
std::string current_hash;
pubkey.Save( StringSink(current_hash));
std::string befores=current_hash.substr (0,22);
CryptoPP::StringSource( befores, true, new CryptoPP::HashFilter(sha1, new
CryptoPP::HexEncoder(new CryptoPP::StringSink(hash_sha1))));
std::string hash_sink;
StringSource ss(hash_sha1.substr (0,20), true,
new Base64Encoder(
new StringSink(boost::algorithm:: to_lower_copy(hash_sink))
) // Base64Decoder
);
std::cout<<"encoded raw:"<<hash_sink<<std::endl;
}
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.