예제 #1
0
        protected override bool TryDecryptEcbCore(
            ReadOnlySpan <byte> ciphertext,
            Span <byte> destination,
            PaddingMode paddingMode,
            out int bytesWritten)
        {
            if (!ValidKeySize(Key.Length, out int keySize))
            {
                throw new InvalidOperationException(SR.Cryptography_InvalidKeySize);
            }

            int effectiveKeySize        = EffectiveKeySizeValue == 0 ? keySize : EffectiveKeySize;
            ILiteSymmetricCipher cipher = CreateLiteCipher(
                CipherMode.ECB,
                paddingMode,
                Key,
                effectiveKeyLength: effectiveKeySize,
                iv: null,
                blockSize: BlockSize / BitsPerByte,
                0, /*feedback size */
                paddingSize: BlockSize / BitsPerByte,
                encrypting: false);

            using (cipher)
            {
                return(UniversalCryptoOneShot.OneShotDecrypt(cipher, paddingMode, ciphertext, destination, out bytesWritten));
            }
        }
예제 #2
0
        protected override bool TryEncryptCfbCore(
            ReadOnlySpan <byte> plaintext,
            ReadOnlySpan <byte> iv,
            Span <byte> destination,
            PaddingMode paddingMode,
            int feedbackSizeInBits,
            out int bytesWritten)
        {
            ValidateCFBFeedbackSize(feedbackSizeInBits);

            ILiteSymmetricCipher cipher = CreateLiteCipher(
                CipherMode.CFB,
                paddingMode,
                Key,
                iv,
                blockSize: BlockSize / BitsPerByte,
                feedbackSizeInBits / BitsPerByte,
                paddingSize: feedbackSizeInBits / BitsPerByte,
                encrypting: true);

            using (cipher)
            {
                return(UniversalCryptoOneShot.OneShotEncrypt(cipher, paddingMode, plaintext, destination, out bytesWritten));
            }
        }
예제 #3
0
        protected override bool TryEncryptEcbCore(
            ReadOnlySpan <byte> plaintext,
            Span <byte> destination,
            PaddingMode paddingMode,
            out int bytesWritten)
        {
            ILiteSymmetricCipher cipher = CreateLiteCipher(
                CipherMode.ECB,
                paddingMode,
                Key,
                iv: null,
                blockSize: BlockSize / BitsPerByte,
                0, /*feedback size */
                paddingSize: BlockSize / BitsPerByte,
                encrypting: true);

            using (cipher)
            {
                return(UniversalCryptoOneShot.OneShotEncrypt(cipher, paddingMode, plaintext, destination, out bytesWritten));
            }
        }
예제 #4
0
        protected override bool TryDecryptCbcCore(
            ReadOnlySpan <byte> ciphertext,
            ReadOnlySpan <byte> iv,
            Span <byte> destination,
            PaddingMode paddingMode,
            out int bytesWritten)
        {
            ILiteSymmetricCipher cipher = CreateLiteCipher(
                CipherMode.CBC,
                paddingMode,
                Key,
                iv,
                blockSize: BlockSize / BitsPerByte,
                0, /*feedback size */
                paddingSize: BlockSize / BitsPerByte,
                encrypting: false);

            using (cipher)
            {
                return(UniversalCryptoOneShot.OneShotDecrypt(cipher, paddingMode, ciphertext, destination, out bytesWritten));
            }
        }