computeSha256 static method

String computeSha256(
  1. Uint8List? data
)

Computes SHA256.

param data Input data. return The result. throws BiosealException An error has occurred during Bioseal Library execution.

Implementation

static String computeSha256(Uint8List? data) {
  Pointer<UnsignedChar>? pData;
  if (data != null) {
  	pData = calloc.allocate<UnsignedChar>(data.length);
  	pData.cast<Uint8>().asTypedList(data.length).setAll(0, data);
  }
  Pointer<Char> pResult = nullptr;
  Pointer<Int> pResultSize = calloc.allocate(1);
  pResultSize[0] = -1;
  try {
    var err = biosealSDK.id3Bioseal_ComputeSha256(pData ?? nullptr, data?.length ?? 0, pResult, pResultSize);
    if (err == BiosealError.insufficientBuffer.value) {
      pResult = calloc.allocate(pResultSize.value);
      err = biosealSDK.id3Bioseal_ComputeSha256(pData ?? nullptr, data?.length ?? 0, pResult, pResultSize);
      if (err != BiosealError.success.value) {
        throw BiosealException(err);
      }
    }
    final vResult = utf8.decode(Uint8List.fromList(pResult.cast<Uint8>().asTypedList(pResultSize.value)));
    return vResult;
  } finally {
    if (pData != null) {
      calloc.free(pData);
    }
    calloc.free(pResult);
    calloc.free(pResultSize);
  }
}