Files
SuperVPN/output/Libraries/BouncyCastle.Crypto/Org/BouncyCastle/Crypto/Paddings/Pkcs7Padding.cs
2025-10-09 09:57:24 +09:00

42 lines
737 B
C#

using Org.BouncyCastle.Security;
namespace Org.BouncyCastle.Crypto.Paddings;
public class Pkcs7Padding : IBlockCipherPadding
{
public string PaddingName => "PKCS7";
public void Init(SecureRandom random)
{
}
public int AddPadding(byte[] input, int inOff)
{
byte b = (byte)(input.Length - inOff);
while (inOff < input.Length)
{
input[inOff] = b;
inOff++;
}
return b;
}
public int PadCount(byte[] input)
{
byte b = input[^1];
int num = b;
if (num < 1 || num > input.Length)
{
throw new InvalidCipherTextException("pad block corrupted");
}
for (int i = 2; i <= num; i++)
{
if (input[^i] != b)
{
throw new InvalidCipherTextException("pad block corrupted");
}
}
return num;
}
}