henrinormak / Heimdall

Heimdall is a wrapper around the Security framework for simple encryption/decryption operations.
MIT License
401 stars 68 forks source link

Use import Public-Key to verify signature #69

Closed t-knapp closed 7 years ago

t-knapp commented 7 years ago

I try to verify a message with a signature. I use a public key in Exponent and Modulus representation. This parameters where passed into Heimdall. I ran into the problem that the message verification failed.

Starting investigations, I noticed, that the byte representation of the original modulus used in Heimdall constructor differs from the output of Heimdall.publicKeyComponents() by one byte. The Heimdall.publicKeyComponents() modulus byte contains an inserted "0x0" at position index 0.

I noticed this step in https://github.com/henrinormak/Heimdall/blob/master/Heimdall/Heimdall.swift#L828 but I did not get the point of this step.

Why is this 0 added in constructor? Does this 0 affect the verify() functionality?

Thanks. Kind regards Tobias

t-knapp commented 7 years ago

Update: I generated a couple new key-pairs with OpenSSL and noticed, that all modulus start with a zero. So I used one of these key-pairs and Heimdall works now.

Nevertheless I'm interested in the reason for this leading zero since the .NET RSA Crypto provider does not generate keys in this manner but these keys also work on Android.

Kind regards Tobias