Example #1
0
        // Expect NoSuchPaddingException
        /// <exception cref="System.Exception"/>
        public virtual void TestUpdateArguments()
        {
            Assume.AssumeTrue(OpensslCipher.GetLoadingFailureReason() == null);
            OpensslCipher cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding");

            Assert.True(cipher != null);
            cipher.Init(OpensslCipher.EncryptMode, key, iv);
            // Require direct buffers
            ByteBuffer input  = ByteBuffer.Allocate(1024);
            ByteBuffer output = ByteBuffer.Allocate(1024);

            try
            {
                cipher.Update(input, output);
                NUnit.Framework.Assert.Fail("Input and output buffer should be direct buffer.");
            }
            catch (ArgumentException e)
            {
                GenericTestUtils.AssertExceptionContains("Direct buffers are required", e);
            }
            // Output buffer length should be sufficient to store output data
            input  = ByteBuffer.AllocateDirect(1024);
            output = ByteBuffer.AllocateDirect(1000);
            try
            {
                cipher.Update(input, output);
                NUnit.Framework.Assert.Fail("Output buffer length should be sufficient " + "to store output data"
                                            );
            }
            catch (ShortBufferException e)
            {
                GenericTestUtils.AssertExceptionContains("Output buffer is not sufficient", e);
            }
        }
Example #2
0
 /// <exception cref="System.IO.IOException"/>
 private void Process(ByteBuffer inBuffer, ByteBuffer outBuffer)
 {
     try
     {
         int inputSize = inBuffer.Remaining();
         // OpensslCipher#update will maintain crypto context.
         int n = cipher.Update(inBuffer, outBuffer);
         if (n < inputSize)
         {
             contextReset = true;
             cipher.DoFinal(outBuffer);
         }
     }
     catch (Exception e)
     {
         throw new IOException(e);
     }
 }