コード例 #1
0
        // PRO: doing this ensure all cipher modes and padding modes supported by .NET will be available with CommonCrypto (drop-in replacements)
        // CON: doing this will only process one block at the time, so it's not ideal for performance, but still a lot better than managed
        protected override void ECB(byte[] input, byte[] output)
        {
            IntPtr          len = IntPtr.Zero;
            CCCryptorStatus s   = Cryptor.CCCryptorUpdate((encrypt == encryption) ? handle : handle_e,
                                                          input, (IntPtr)input.Length, output, (IntPtr)output.Length, ref len);

            if (((int)len != output.Length) || (s != CCCryptorStatus.Success))
            {
                throw new CryptographicUnexpectedOperationException(s.ToString());
            }
        }
コード例 #2
0
        int Transform(byte[] input, int inputOffset, byte[] output, int outputOffset, int length)
        {
            IntPtr len     = IntPtr.Zero;
            IntPtr in_len  = (IntPtr)length;
            IntPtr out_len = (IntPtr)(output.Length - outputOffset);

            fixed(byte *inputBuffer = &input[0])
            fixed(byte *outputBuffer = &output [0])
            {
                CCCryptorStatus s = Cryptor.CCCryptorUpdate(handle, (IntPtr)(inputBuffer + inputOffset), in_len, (IntPtr)(outputBuffer + outputOffset), out_len, ref len);

                if (s != CCCryptorStatus.Success)
                {
                    throw new CryptographicException(s.ToString());
                }
            }
            return((int)len);
        }