using System;
namespace Renci.SshNet.Security.Cryptography.Ciphers.Paddings
{
///
/// Implements PKCS7 cipher padding
///
public class PKCS7Padding : CipherPadding
{
///
/// Pads the specified input to match the block size.
///
/// The size of the block.
/// The input.
/// The zero-based offset in at which the data to pad starts.
/// The number of bytes in to take into account.
///
/// The padded data array.
///
public override byte[] Pad(int blockSize, byte[] input, int offset, int length)
{
var numOfPaddedBytes = blockSize - (length % blockSize);
return Pad(input, offset, length, numOfPaddedBytes);
}
///
/// Pads the specified input with a given number of bytes.
///
/// The input.
/// The zero-based offset in at which the data to pad starts.
/// The number of bytes in to take into account.
/// The number of bytes to pad the input with.
///
/// The padded data array.
///
public override byte[] Pad(byte[] input, int offset, int length, int paddinglength)
{
var output = new byte[length + paddinglength];
Buffer.BlockCopy(input, offset, output, 0, length);
for (var i = 0; i < paddinglength; i++)
{
output[length + i] = (byte) paddinglength;
}
return output;
}
}
}