internal MagmaManagedTransform(
     byte[] rgbKey,
     byte[] rgbIV,
     int blockSize,
     CipherMode cipherMode,
     PaddingMode paddingMode,
     SymmetricTransformMode transformMode)
     : base(rgbKey, rgbIV, blockSize, cipherMode, paddingMode, transformMode)
 {
 }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SymmetricTransform" /> class.
        /// </summary>
        /// <param name="key">
        /// The secret key to be used for the symmetric algorithm.
        /// </param>
        /// <param name="iv">
        /// The initialization vector (<see cref="SymmetricAlgorithm.IV" />) to be used
        /// for the symmetric algorithm.
        /// </param>
        /// <param name="blockSize">
        /// The block size, in bits, of the cryptographic operation.
        /// </param>
        /// <param name="cipherMode">
        /// The mode for operation of the symmetric transform.
        /// </param>
        /// <param name="paddingMode">
        /// The padding mode used in the symmetric transform.
        /// </param>
        /// <param name="transformMode">
        /// The direction mode of the symmetric transform.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="key"/> parameter is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="iv"/> parameter is <see langword="null"/> when <paramref name="cipherMode"/> value is
        /// <see cref="CipherMode.CBC"/>, <see cref="CipherMode.CFB"/> or <see cref="CipherMode.OFB"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="blockSize"/> parameter is non-positive.
        /// </exception>
        /// <exception cref="CryptographicException">
        /// <paramref name="cipherMode"/> parameter value is not supported.
        /// </exception>
        protected SymmetricTransform(
            byte[] key,
            byte[]?iv,
            int blockSize,
            CipherMode cipherMode,
            PaddingMode paddingMode,
            SymmetricTransformMode transformMode)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (blockSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(blockSize),
                                                      CryptographyStrings.ArgumentOutOfRangeNeedPositiveNum);
            }

            _transformMode = transformMode;
            InputBlockSize = blockSize / 8;
            _cipherMode    = cipherMode;
            _paddingMode   = paddingMode;

            switch (_cipherMode)
            {
            case CipherMode.ECB:
                break;

            case CipherMode.CBC:
            case CipherMode.CFB:
            case CipherMode.OFB:
                if (iv == null)
                {
                    throw new ArgumentNullException(nameof(iv));
                }
                _rgbIV       = (byte[])iv.Clone();
                _stateBuffer = new byte[_rgbIV.Length];
                _tempBuffer  = new byte[InputBlockSize];
                Reset();
                break;

            default:
                throw new CryptographicException(CryptographyStrings.CryptographicInvalidCipherMode);
            }

            _rgbKey = (byte[])key.Clone();
        }
示例#3
0
 private ICryptoTransform CreateTransform(byte[] rgbKey, byte[] rgbIV, SymmetricTransformMode transformMode)
 => new SimpleSymmetricTransform(rgbKey, rgbIV, BlockSizeValue, ModeValue, PaddingValue, transformMode);