Org.BouncyCastle.Crypto.BufferedBlockCipher.GetOutputSize C# (CSharp) Method

GetOutputSize() public method

public GetOutputSize ( int length ) : int
length int
return int
		public override int GetOutputSize(
			int length)
		{
			int total = length + bufOff;
			int leftOver = total % buf.Length;
			if (leftOver == 0)
			{
				return total;
			}
			return total - leftOver + buf.Length;
		}

Usage Example

Example #1
0
            public string GenerateActivationKey()
            {
                var engine = new BlowfishEngine();
                var cipher = new CbcBlockCipher(engine);
                var bbc = new BufferedBlockCipher(cipher);
                bbc.Init(true, new ParametersWithIV(new KeyParameter(Encoding.ASCII.GetBytes(EncKey)), IV));

                var n = Prng.Next(0, 999999);

                var s = String.Format("{0,6};YNAB4;;;;", n); // must be fixed length due to padding issue
                var sb = Encoding.ASCII.GetBytes(s);
                sb[sb.Length - 4] = 0x4; //
                sb[sb.Length - 3] = 0x4; // padding issue???
                sb[sb.Length - 2] = 0x4; // PCKS#5
                sb[sb.Length - 1] = 0x4; //
                var cipherText = new byte[bbc.GetOutputSize(sb.Length)];
                var outputLen = bbc.ProcessBytes(sb, 0, sb.Length, cipherText, 0);
                bbc.DoFinal(sb, outputLen);
                var encryptedLic = Base32.EncodeByteArray(cipherText);

                return encryptedLic;
            }