encode method

Uint8List encode(
  1. int blockSize,
  2. List<int> input
)

Implementation

Uint8List encode(int blockSize, List<int> input) {
  final mHash = hasher.convert(input).bytes;

  if (blockSize < mHash.length + saltLength + 2) {
    throw Exception('encoding error. blockSize too small');
  }

  Random random = Random.secure();

  final salt = List<int>.generate(saltLength, (index) => random.nextInt(256));

  final mDash = <int>[
    ...List<int>.filled(8, 0),
    ...mHash,
    ...salt,
  ];

  final h = hasher.convert(mDash).bytes;

  final ps = List.filled(blockSize - saltLength - mHash.length - 2, 0);

  final db = <int>[
    ...ps,
    0x01,
    ...salt,
  ];

  final dbMask = mgf.encode(blockSize - mHash.length - 1, h);

  final maskedDb = ListOps.xor(db, dbMask);

  final em = Uint8List.fromList(<int>[
    ...maskedDb,
    ...h,
    0xbc,
  ]);

  return em;
}