ed25519KeyIdentityFromPem function
Implementation
Future<Ed25519KeyIdentity> ed25519KeyIdentityFromPem(String pem) async {
final privateKeyPem = pem
.replaceAll('-----END PRIVATE KEY-----', '')
.replaceAll(RegExp(r'\n+'), '')
.replaceAll(RegExp(r'\s+'), '')
.trim()
.replaceAll('r[^0-9a-zA-Z/+]', '');
final keyBytes = base64Decode(privateKeyPem);
final ASN1Parser p = ASN1Parser(keyBytes);
final ASN1Sequence seq = p.nextObject() as ASN1Sequence;
final ASN1Parser p2 = ASN1Parser(seq.elements?[2].valueBytes);
final octetStringSeq = p2.nextObject() as ASN1OctetString;
final res = octetStringSeq.valueBytes!;
return Ed25519KeyIdentity.generate(res);
}