hohl / MIHCrypto

OpenSSL wrapper for Objective-C [cryptography]
MIT License
340 stars 66 forks source link

Obtain public key data in a common format #36

Closed GabrieleCocco closed 8 years ago

GabrieleCocco commented 8 years ago

Hi, i gotta say this is the only library I found in months or research that allows to -easily- handle keys, signature and encryption in iOS: great job! I'm using it to sign data that must be sent (signed) together with public key to a cloud service for authentication. Unfortunately, I'm having troubles "exporting" the public key in a format that can be used by .NET. As a matter of fact, I also tried to copy+paste the signed data and the result of calling dataValue on the public key to a file and then use command line openssl verify:

openssl rsautl -verify -inkey ~/Desktop/pubkey.pem -in ~/Desktop/datasigned.txt -pubin -raw -hexdump

Resulting in: unable to load Public Key I guess what is missing is the algorithm OID, which would be useful.

Did you test the dataValue result agains out-of-project signature verification tools? Thanks!

akhilstanis commented 8 years ago

openssl rsautl by default expects the -inkey parameter to be in PEM in format, but MIHRSAPublicKey#dataValue method returns the public key in DER format. You can use DER formatted keys with openssl rsautl by setting -keyform parameter to DER

GabrieleCocco commented 8 years ago

I managed to use PEM anyway by manually (re)adding the header stripped in dataValue function. Seems to work ok in .NET as well. Thanks.

hohl commented 8 years ago

Sorry, for not supporting multiple formats with dataValue. I'm aware that dataValue is small miss-design in the library, that's why there is already a draft for a different way to export keys by defining a data format - however yet, I didn't find time to implement it - see #9 for more details.