I have an XML file that is in this format:

    Test string

I was able to produce the SHA256 and produced a string by using the following:

string CalculateSHA256(const string& input)
    SHA256 hash;
    string digest;
    StringSource _(input, true, new HashFilter(hash, new HexEncoder (new StringSink(digest))));
    return digest;

In the documentation I have it mentions that a signature can be verified by using PKCS, SHA256, and a public key. I have the public key and like i mentioned about SHA256, but I cannot find a way to produce the signature. I have the string of what I SHOULD be, but im trying to verify it was correctly produced.

The methods that I've tried have produced signatures with random non ascii characters. Any help would be great. Thanks!

It appears to me to be the fact that the contained string simply has additional characters other than what you "see". Try removing the additional carriage return and spaces within the XML as follows and then see if you get a match.


What ive come to find out is that the ASCII needs to be converted to hex. That hex value is what im really looking for. I am able to do that conversion very easily actually, so my main problem is understanding what content the signer should be taking in to get the output im expecting.

So here my update:

I am able to do the SHA256 and PKCSS1.5 via this code:

string signature2;
    // Sign and Encode
    RSASS<PKCS1v15, SHA256>::Signer signer2(privateKey);
    StringSource(content, true, new SignerFilter(rng, signer2, new StringSink(signature2)));

And then have it converted to HEX via this code:

string digest;
    StringSource (signature.m_ptr, true, new HexEncoder(new StringSink(digest)));

My problem now falls on the string "content". I believe the XML file im trying to perform the filtering on is not exactly like my precalculated example i am referencing. Every space, every new line, everything can change the outcome of the the final hex value, so im sure im VERY close but still not exact.

My question is, when doing the signing is there a typical format for it? Or is it one of those things that it completely matters on my application?

Again, for me, I would remove the additional/unnecessary characters (tab, space, cr/lf) within the field to be sure of what you actually have. Try debugging and seeing if they're included within your variable, I'm pretty sure they are. Everything is taken as a literal with nothing being stripped off, unless you do it yourself, of course.

Glad to hear the other portion seems to be fine.

In my case I shouldnt be removing anything. LIke you mentnioned everything is taken literally with nothing being stripped.

something Im considering now is since I can correctly perform the SHA256 and produce the hex value, can I somehow perform the PKCS 1.5 on my already calculated SHA256? I've been able to do:

RSASS<PKCS1v15, SHA256>::Signer signer1(privateKey);

But in this case I want just the PKCS1V15 component.

As a last update. It turns out there is not way to produce the same signature since I don't have the original priviate key. I do though have the ability to verify it, and that was the whole reason in producing the same signature. Question is solved for me. Thanks!

Sorry I hadn't answered earlier today, pretty busy, but I'm glad you solved it.