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' })