EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Format for embedding public key in source

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#34952
Posted: 11/07/2015 08:29:02
by David Rivera (Priority Standard support level)
Joined: 07/30/2015
Posts: 7

I'd like to embed the public key from a certificate to be used for verifying XML signatures with XMLBlackbox under Windows. I'm having a hard time finding info on what the format of the public key should be. Ideally, I'd just hardcode a byte array using the public key that I manually copy from the certificate. I could Base-64 encode that array also.

I'm assuming I would use TElXMLKeyInfoRSAData.LoadPublic, but I can't figure out if that public key is supposed to be in some specific format, or if there's some way I'm supposed to format that raw data so I don't get an 'Invalid public key' exception.

Interested primarily in C++, but may also want to do something similar in C#.
#34953
Posted: 11/07/2015 10:43:13
by Eugene Mayevski (EldoS Corp.)

RSA keys have a common format for saving. TElRSAKeyMaterial class has LoadPublic/SavePublic methods which you can use for loading and saving the key from / to the buffer. The buffer can then be encoded/decoded with base64 if needed.

Moreover TElRSAKeyMaterial class also has LoadFromXML/SaveToXML methods which load and save the key in XML format.

TElXMLKeyInfoRSAData has KeyMaterial property of type TElRSAKeyMaterial (the property is pre-initialized with the object, so you don't need to create yours). So you can call something like TElXMLKeyInfoRSAData.KeyMaterial.LoadPublic().


Sincerely yours
Eugene Mayevski
#34964
Posted: 11/09/2015 15:12:53
by David Rivera (Priority Standard support level)
Joined: 07/30/2015
Posts: 7

Thank you for this. How do I get access to TElXMLKeyInfoRSAData.KeyMaterial? This does not seem to be an available property of the class in the C++ library. I think this is ultimately the problem I'm having -- getting access to the KeyMaterial in a TElMLKeyInfoRSAData object.

More specifically, here is what I've tried:

TElXMLKeyInfoRSAData RSAKeyData(true);
TElRSAKeyMaterial *key = RSAKeyData.get_RSAKeyMaterial();
key->Load(pBuffer, size);

The 'load' call results in the exception.

pBuffer and size are the exact values I got from SavePublic()
#34965
Posted: 11/09/2015 15:48:06
by Dmytro Bogatskyy (EldoS Corp.)

Hi,

Quote
pBuffer and size are the exact values I got from SavePublic()

Please use the corresponding TElRSAKeyMaterial.LoadPublic() method, see:
https://www.eldos.com/documentation/sb...ublic.html
The Load() method expects the stream object as input, that's why you get the exception.
#34966
Posted: 11/09/2015 16:22:45
by David Rivera (Priority Standard support level)
Joined: 07/30/2015
Posts: 7

Here is sample code for what I've tried. I get an exception on the LoadPublic call.

Note that it works fine if I use SaveToXML and LoadFromXML instead.

(I removed the license key from the attached).

I'm using Visual Studio 2015.


[ Download ]
#34967
Posted: 11/09/2015 17:16:56
by Dmytro Bogatskyy (EldoS Corp.)

Hi,
Quote
Here is sample code for what I've tried. I get an exception on the LoadPublic call.

Please try to set RawPublicKey property before loading the key from a buffer, for example:
Code
key->set_RawPublicKey(true);
#34976
Posted: 11/10/2015 12:52:43
by David Rivera (Priority Standard support level)
Joined: 07/30/2015
Posts: 7

That worked, thank you.

Just curious, is there some other format other than "raw" that can be used with the LoadPublic method? Seems like raw would be assumed by the LoadPublic method.
#34977
Posted: 11/10/2015 13:16:51
by Eugene Mayevski (EldoS Corp.)

There exist two formats:

Sequence(PublicModulus, PublicExponent) // Raw
and
Sequence(OID, SEQUENCE(PublicModulus, PublicExponent))

our classes can write and read keys in both formats. It is important, though, that the writer and the reader use the same format.


Sincerely yours
Eugene Mayevski
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 2787 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!