Org.BouncyCastle.Crypto.Encodings.Pkcs1Encoding.EncodeBlock C# (CSharp) Method

EncodeBlock() private method

private EncodeBlock ( byte input, int inOff, int inLen ) : byte[]
input byte
inOff int
inLen int
return byte[]
		private byte[] EncodeBlock(
			byte[]	input,
			int		inOff,
			int		inLen)
		{
	        if (inLen > GetInputBlockSize())
	            throw new ArgumentException("input data too large", "inLen");

	        byte[] block = new byte[engine.GetInputBlockSize()];

			if (forPrivateKey)
			{
				block[0] = 0x01;                        // type code 1

				for (int i = 1; i != block.Length - inLen - 1; i++)
				{
					block[i] = (byte)0xFF;
				}
			}
			else
			{
				random.NextBytes(block);                // random fill

				block[0] = 0x02;                        // type code 2

				//
				// a zero byte marks the end of the padding, so all
				// the pad bytes must be non-zero.
				//
				for (int i = 1; i != block.Length - inLen - 1; i++)
				{
					while (block[i] == 0)
					{
						block[i] = (byte)random.NextInt();
					}
				}
			}

			block[block.Length - inLen - 1] = 0x00;       // mark the end of the padding
			Array.Copy(input, inOff, block, block.Length - inLen, inLen);

			return engine.ProcessBlock(block, 0, block.Length);
		}