You have put me on the right track, but I cannot find a way to change the key 
size or block size  in the BouncyCastle Portable class library implementation.  
My Rijndael implementation has a KeySize of 256 and a BlockSize of 128.  Both 
the  PaddedBufferedBlockCipher.GetBlockSize() and AesEngine.GetBlockSize() 
return 16.

My code looks like this
public class BouncyCastleEngine : CryptoBase, ICrypto
{
      private Encoding _encoding;
      private IBlockCipher _blockCipher;
      private PaddedBufferedBlockCipher _cipher;
      private IBlockCipherPadding _padding;

      public BouncyCastleEngine()
      {

             _blockCipher = new AesEngine();
             _encoding = Encoding.UTF8;
             _padding = new ZeroBytePadding();
      }

      public string Encrypt(string plain, string key)
      {
             if (plain == null)
                   throw new ArgumentNullException(nameof(plain));
             if (key == null)
                   throw new ArgumentNullException(nameof(key));

             var plainBytes = _encoding.GetBytes(plain);
             var keyBytes = _encoding.GetBytes(key);
             byte[] result = _bouncyCastleCrypto(true, plainBytes, keyBytes);

return ToHexString(result);
      }

      public string Decrypt(string hexString, string key)[Jaco De Villiers] {…}
      private byte[] _bouncyCastleCrypto(bool forEncrypt, byte[] input, byte[] 
keyByte)
      {
             _cipher = _padding == null ? new 
PaddedBufferedBlockCipher(_blockCipher) : new 
PaddedBufferedBlockCipher(_blockCipher, _padding);
             _cipher.Init(forEncrypt, new KeyParameter(keyByte));
             return _cipher.DoFinal(input);
      }
}

Reply via email to