decodeBase64 static method

Uint8List decodeBase64(
  1. String value
)

Decodes canonical padded RFC 4648 standard Base64.

Implementation

static Uint8List decodeBase64(String value) {
  if (value.length % 4 != 0 || !_base64Pattern.hasMatch(value)) {
    throw InvalidInputException('Invalid canonical Base64 input');
  }

  try {
    final decoded = base64.decode(value);
    if (base64.encode(decoded) != value) {
      throw InvalidInputException('Invalid canonical Base64 input');
    }
    return Uint8List.fromList(decoded);
  } on FormatException {
    throw InvalidInputException('Invalid canonical Base64 input');
  }
}