splitSecretToBigInt method

List<BigInt> splitSecretToBigInt(
  1. String secret
)

Converts a byte array into an a 256-bit BigInt, array based upon size of the input byte; all values are right-padded to length 256 bit, even if the most significant bit is zero.

Implementation

List<BigInt> splitSecretToBigInt(String secret) {
  List<BigInt> rs = [];
  if (secret.isNotEmpty) {
    String hexData = HEX.encode(utf8.encode(secret));
    int count = (hexData.length / 64.0).ceil();
    for (int i = 0; i < count; i++) {
      if ((i + 1) * 64 < hexData.length) {
        BigInt bi = BigInt.parse(hexData.substring(i * 64, (i + 1) * 64), radix: 16);
        rs.add(bi);
      } else {
        String last = hexData.substring(i * 64, hexData.length);
        int n = 64 - last.length;
        for (int j = 0; j < n; j++) {
          last += "0";
        }
        BigInt bi = BigInt.parse(last, radix: 16);
        rs.add(bi);
      }
    }
  }
  return rs;
}