decodeBls12381PrivateKeyPkcs8 static method
Implementation
static SecretBytes decodeBls12381PrivateKeyPkcs8(List<int> der) {
final root = DerReader(der).readNode();
_expectTag(root, DerTag.sequence, 'PrivateKeyInfo SEQUENCE');
final fields = root.children();
if (fields.length < 3) {
throw CoreErrors.cryptoFailed(
"decodeBls12381PrivateKeyPkcs8",
reason: 'Malformed PrivateKeyInfo',
);
}
_expectTag(fields[0], DerTag.integer, 'version');
final algId = fields[1];
_expectTag(algId, DerTag.sequence, 'AlgorithmIdentifier');
final algFields = algId.children();
if (algFields.isEmpty) {
throw CoreErrors.cryptoFailed(
"decodeBls12381PrivateKeyPkcs8",
reason: 'Malformed AlgorithmIdentifier',
);
}
_expectTag(algFields[0], DerTag.oid, 'algorithm OID');
final algOid = DerUtils.decodeOid(algFields[0].value);
if (algOid != Oids.icBls12381) {
throw CoreErrors.cryptoFailed(
"decodeBls12381PrivateKeyPkcs8",
reason: 'Not an IC BLS12-381 key (algorithm OID $algOid)',
);
}
_expectTag(fields[2], DerTag.octetString, 'privateKey');
return decodeBls12381PrivateKeyRaw(fields[2].value, wipeSource: true);
}