decodeToDER static method
Read possible PEM encoding
Implementation
static Uint8List? decodeToDER({required pemData}) {
var pem = String.fromCharCodes(pemData);
if (pem.contains(X509Certificate.beginPemBlock)) {
var lines = pem.split("\n");
var base64buffer = "";
var certLine = false;
for (var line in lines) {
if (line == X509Certificate.endPemBlock) {
certLine = false;
}
if (certLine) {
base64buffer += line;
}
if (line == X509Certificate.beginPemBlock) {
certLine = true;
}
}
Uint8List? derDataDecoded;
try {
derDataDecoded = Uint8List.fromList(utf8.encode(base64buffer));
} catch (e) {}
if (derDataDecoded != null) {
return derDataDecoded;
}
}
return null;
}