Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1x 1x 147x 147x 139x 139x | import randomBytes from 'randombytes'; import type { IPadding } from './IPadding'; export class ISO10126Padding implements IPadding { public addTo(data: Uint8Array, blockSize: number): Uint8Array { const paddingLength = blockSize - data.length % blockSize; return new Uint8Array([...data, ...randomBytes(paddingLength - 1), paddingLength]); } public removeFrom(data: Uint8Array): Uint8Array { const paddingLength = data[data.length - 1]; return data.slice(0, data.length - paddingLength); } } |