0

So I'm currently working on a web service for Amazon Alexa. For their request authentication, I'm downloading and validating a certificate. Afterwards I shall decrypt a signature with the certificate's public key. Now I've tried some things with Poco and OpenSSL, never getting a fitting result.

One example as a try for OpenSSL:

void decryptWithPublicKey(const std::string & input, const std::shared_ptr<Poco::Crypto::X509Certificate> & cert, std::string & buffer)
{
     RSA * decryptor = Poco::Crypto::RSAKey(*key).impl()->getRSA();
     const unsigned char * from = (const unsigned char*) input.c_str();
     unsigned char* to = new unsigned char[ RSA_size(decryptor)-12 ];;

     int result = RSA_public_decrypt((int) input.length(), from, to, decryptor, RSA_PKCS1_PADDING);
     if(result == -1)
     {
         // print error
     }
     else
     {
         buffer.append((char*) to);
     }

     delete from;
     delete[] to;
}

Output is always sth like "0!0 +\n PuTTYPuTTY"

Anyone has any experience with that?

jww
  • 97,681
  • 90
  • 411
  • 885
be_bri
  • 61
  • 6
  • The language either *is* or *isn't* C. This isn't. – Antti Haapala -- Слава Україні Mar 20 '17 at 12:49
  • *"Decrypt with Public Key"* is not a valid cryptographic operation. Maybe you want a *Probabilistic Signature Scheme with Recovery (PSSR)* instead? – jww Mar 20 '17 at 13:20
  • @AnttiHaapala - It appears to be both. OpenSSL is a C library, and he is using it in C++. C++ was intended to be a superset of C, but they have slightly differing behaviors in a few areas that could be affecting the problem. [Unions and inactive member access](http://stackoverflow.com/q/11373203/608639) comes to mind for me because it bit me a few times. – jww Mar 20 '17 at 13:24
  • @jww that's why I tagged both. And Yes, I know, but I haven't read about PSSR, yet. Do you know any C/C++ implementation of said scheme? – be_bri Mar 20 '17 at 14:34
  • @be_bri - *"Do you know any C/C++ implementation of [PSSR]"* - Jack Lloyd's [Botan](https://botan.randombit.net/) or Wei Dai's [Crypto++](https://www.cryptopp.com/). – jww Mar 20 '17 at 14:39

0 Answers0