Decrypt using RSA private key using windows crypto api - c++

I have a RSA private key in xml format.
<?xml version="1.0" encoding="utf-16"?>
<RSAParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Exponent>....</Exponent>
<Modulus>....</Modulus>
<P>....</P>
<Q>....</Q>
<DP>....</DP>
<DQ>....</DQ>
<InverseQ>....</InverseQ>
<D>....</D>
</RSAParameters>
I have to decrypt some data in C++. I want to use Windows Crypto API in C++.
I am new into C++ and crypto. Cannot find any good sample code for this.
I am finding MSDN documentation a bit not for beginners. All I need is a set of library functions to read my private key from XML and decrypt some data. In C#, it is very straightforward. Don't understand why so complicated in C++.
Can anyone help me with the steps or sample codes or some beginner level resources for this.

Related

how do or what is the best way to generate AES key using openssl programmatically?

how do or what is the best way to generate AES key using openssl programmatically? Saw recommendations using RAND_bytes. I also come across this API — AES_set_encrypt_key(....). But the first parameter seems to be user’s encrypted key. So, I think you I need to generate an AES key first b4 calling this API.
Please advise

How i can use Cryptography library to encryption files in python

I'm trying to encrypt and decrypt PDF file using crypto and everything works well but I need to use another library like Cryptography https://github.com/pyca/cryptography .
How I can use Cryptography library to encrypt and decrypt files like PDF file because I search a lot and I can't find one example of how I can use Cryptography with files.
Any example may help.
To answer your question Cryptography's documentation could potentially help you with this. I used the library to encrypt text files, python files, i not sure about pdf's though. But the doc's were helpful. https://cryptography.io/en/latest/
Plus this website also helped me out as well.
https://www.thepythoncode.com/article/encrypt-decrypt-files-symmetric-python
It implements the Fernet key type encryption which is symmetric encryption.
There is asymmetric encryption (I believe this type uses public and private keys) you can as far i know encrypt strings with this type of encryption. As far as encrypting files with this type of encryption i am not sure about that as i have not done any research on that my self lol!
I was messing around with some of the functions in this library and found some useful things in it. Hope this helps.
p.s. Stay away from the hazmat section of this library. ONLY use this if you really know what your doing in terms of cryptography!

BB Download a XML from String url

I figured how to use RapidXML a C++ Lib to parse pretty much everything from my XML provided by my API what I need to do now is actually get the XML on to my BlackBerry Dev Alpha B running a BB 10.2.0
What would be the proper way to download a XML file via String/url. Also any fellow developers here who made the transition from Android/Java to BB/C++ any recommendations on how to make the transition smoother.

How to control Spring-WS namespace single or double quote with XSLT

I want to change the double quotes to single quotes for a single namespace declaration in my document, while leaving all other namespace declarations as double quotes. How can I do this?
Here's the response document from the server:
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><InquiryResponse
xmlns="http://www.openuri.org/"><Header><HeaderAttr1>abcd</HeaderAttr1><HeaderAttr2>xxx</HeaderAttr2><HeaderAttr3>string</HeaderAttr3></Header><Body><InquiryResult><ResultItem1>theresulttext</ResultItem1><ResultItem2>abcd</ResultItem2><ResultItem3>0</ResultItem3></InquiryResult></Body></InquiryResponse></soapenv:Body></soapenv:Envelope>
I need something like (note that open:InquiryResponse has ' not ").
<?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body>
<open:InquiryResponse
xmlns:open='http://www.openuri.org/'><open:Header><open:HeaderAttr1>abcd</open:HeaderAttr1><open:HeaderAttr2>xxx</open:HeaderAttr2><open:HeaderAttr3>string</open:HeaderAttr3></open:Header><open:Body><open:InquiryResult><open:ResultItem1>theresulttext</open:ResultItem1><open:ResultItem2>abcd</open:ResultItem2><open:ResultItem3>0</open:ResultItem3></open:InquiryResult></open:Body></open:InquiryResponse>
</SOAP-ENV:Body> </SOAP-ENV:Envelope>
I have been able to do namespace prefix change, additional namespace declarations, whitespace fixups, character set change, all I need now is to change those two bytes.
I'm using Spring WS + Woodstox + Axiom to build a simple inquiry web service. It's a replacement for an existing service and I would like to make it byte-for-byte identical ($$ reasons). I can get the XML to identical type, but we don't know at this point which consumers use a grep or regex to find the data.
I am trying to attack this problem so far using an XSLT and PayloadTransformingInterceptor. I would be interested in other options as well.
Comments are pretty much correct: there is no "clean" programmatic solution to configuring low-levels with such precision. And given fragility, you are best off using textual mangling; most likely regexps would work well enough if this is for testing or such.
After re-reading your question and examples a few times I think I understand the problem :)
I think you should take a look at the PayloadTransformingInterceptor. You can transform the incoming and outgoing messages in that interceptor. A typical usage of that interceptor is to support an older version of your wsdl by transforming it to the new version. This interceptor can work both ways - in your case only outgoing.
I'm not sure if this can be fixed by using XSLT. If not, you can create your own Interceptor to provide the specific string replacement functionality you need.
The solution was to drop Spring-WS, and instead move to CXF. CXF allows interceptors at any stage of processing, and hence full access to the bytes of the message stream. Ugly, but working. Build an interceptor to hook the OutputStream at PRE_STREAM and then do the fix at PRE_STREAM_ENDING, and you will have full control over the SOAP Envelope.
Thank you all for your responses. It sucks but it works, and is reasonably easy to disconnect when we have the time to do it properly (!!).

How to sign XML document or verify XML document signature with C++?

Subj. I need to sign/verify under Windows in native C++ (no .NET), using private key for signing, public key for verification.
I saw few examples on MSDN (http://msdn.microsoft.com/en-us/library/ms761363(VS.85).aspx) that demonstrate how to sign the document with CSP (I don't know what this means).
For my case I need to use a "key" from the binary data array (using DSA encryption algorithm)... can somebody help me with that?
Thank you in advance.
I recommand libxml2 and xmlsec which are perfect for this purpose.
The API can seem hard to read at first, but it works well. xmlsec uses OpenSSL to achieve the cryptographic part.
Providing a "short" example here is probably hard because the three libraries require some initialization and a lot of C calls.
Google's keyczar lib is also very easy to use
There's also Crypto++