Open naftulikay opened 4 months ago
I don't think this is a problem within ed25519-dalek
, as I have verified things externally using the openssl
CLI. I generated a key-pair, wrote the PEM format to public.pem
, the DER format to public.der
, and then ran the following to convert the PEM to DER:
openssl pkey -in public.pem -pubin -outform der -out public.openssl.der
I then compared the contents, and they are the same:
$ sha256sum public.der public.openssl.der
a17fcf0a2f50e2d495e4f90ce263410edc183add6c62699a2facbccf60410f74 public.der
a17fcf0a2f50e2d495e4f90ce263410edc183add6c62699a2facbccf60410f74 public.openssl.der
Therefore it seems that there is a problem within the DecodingKey::from_ed_der
method.
I also just attempted to use the private key DER bytes to create a DecodingKey
:
let private_der = dalek_private.to_pkcs8_der().unwrap();
let decoding_key = DecodingKey::from_ed_der(private_der.as_bytes());
This also fails verification. It seems the only thing that I can do is use PEM. I may try some of the other options as well.
I'm generating ed25519 keys using
ed25519-dalek
and therand
crates, and while I can sign and verify using public key PEM encoding, verification fails when using public key DER encoding.Cargo.toml:
Here is a test case which generates a keypair, converts it into
jsonwebtoken
types, and successfully signs and verifies a signature:tests/test_alpha.rs:
The above code does pass the test, but note that I'm converting my public ed25519 key to PEM format, and creating a
DecodingKey
usingDecodingKey::from_ed_pem
:My private key converts just fine when using DER encoding, but the public key seems to be the problem. If I change the above code to use DER for the public key, the test fails:
Just changing the
DecodingKey
from PEM format to DER format causes the verification to fail.Am I doing something wrong here when trying to work with DER format? Is it possible that the DER format emitted by ed25519-dalek is incompatible with this library, and if so, what can I do to determine where the incompatibility is coming from?