How to create a certificate(X509Certificate) in Dart?
2,060
Take a look at the very last test in the package test routines.
Try the named constructor for parsing DER files.
var f = File('test/resources/rfc5280_cert1.cer');
var bytes = f.readAsBytesSync(); // this is the byte array
var c = X509Certificate.fromAsn1(ASN1Parser(bytes).nextObject());
![Uday](https://i.stack.imgur.com/YfTVA.jpg?s=256&g=1)
Author by
Uday
Updated on December 22, 2022Comments
-
Uday over 1 year
How to create the Certificate in Dart.
I used to create the following certificate in java, Can we convert the following Java code to Dart?
Where the "certBytes" is a byte array in which I will be getting certificate data.
byte[] certBytes = new byte[]{(byte) 0x00, (byte) 0x01, (byte) 0x22, (byte) 0x7E}; InputStream in = new ByteArrayInputStream(certBytes); X509Certificate certificate = null; try { CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); certificate = (X509Certificate) certFactory.generateCertificate(in); }
-
Richard Heap almost 4 yearsThis package expects a PEM format but you could probably adapt it to a DER input. pub.dev/packages/x509
-
Uday almost 4 years@RichardHeap do I need to convert my byte array into PEM file and pass it to that lib?
-
Uday almost 4 yearsAny Example code will be helpful for others too.
-
Richard Heap almost 4 yearsNormally, it expects a PEM string, but it also provides a
.fromAsn1
named constructor. Check out the very last test as an example.
-
-
Uday almost 4 yearsI tried overriding this method
_parseDer(bytes, type);
, which is in this class github.com/appsupdart/x509/blob/master/lib/src/x509_base.dart. where bytes are my DER byteArray & for type I tried empty string & "IN PUBLIC KEY". but it throws Unhandled Exception: UnimplementedError -
Uday almost 4 yearsI have a DER byte array, can I get the public Key out of it?
-
Richard Heap almost 4 yearsUse this as some sample code: stackoverflow.com/questions/54726406/…