0

I want to generate PEM string for the public key generated using ED25519 algorithm in Dart. But I am not able to find any suitable way to do so.

I have used Cryptography package to generate the key pair as follows:

final keyPair = await Ed25519().newKeyPair();

Then I retrieved the bytes from the public key generated from the above command as follows:

keyPair.extractPublicKey().then((key) => key.bytes)

So now I have a List<int> which is supposedly the bytes of the public key.

I want to now generate a DER encoded PEM string to send the public key to my server.

I am not able to find any way to do this.

I tried various other packages but none of them helps me export the key as PEM.

Basically, I want to create the key back in my node JS server as follows:

crypto.createPublicKey({ key: Buffer.from(publicKeyPEM, 'utf-8'), format: 'pem', type: 'spki' })

Abhishek729
  • 327
  • 5
  • 14
  • 1
    The public keys have different format (as you already figured out yourself), raw on the Dart side, X.509/SPKI on the NodeJS side. This post [_Convert node.js cryptography code into dart_](https://stackoverflow.com/q/68668632/9014097) about Ed25519 is quite similar, in one of the comments you can find the conversion rule. – Topaco Sep 25 '21 at 20:29
  • Thank you @Topaco. Using the information shared in the post your shared, I am now able to successfully export the public key which server can use to verify the signature :) – Abhishek729 Sep 27 '21 at 01:55

0 Answers0