예제 #1
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public RC2CryptoServiceProvider()
        {
            // .NET Framework 2.0 - 4.7.2 rejected RC2 when in FIPS mode because it was not
            // an approved algorithm. For applications which needed to have FIPS mode enabled
            // but also process data encrypted with RC2 there was no good option (the most
            // plausible scenario is decrypting previously encrypted data, since FIPS policies
            // mainly restrict applying algorithms to plaintext).
            //
            // An application or library will have to determine on its if RC2 is prohibited in context.
            if (CryptoConfig.AllowOnlyFipsAlgorithms && AppContextSwitches.UseLegacyFipsThrow)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
            }
            Contract.EndContractBlock();
            if (!Utils.HasAlgorithm(Constants.CALG_RC2, 0))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgorithmNotAvailable"));
            }

            // Acquire a Type 1 provider. This will be the Enhanced provider if available, otherwise
            // it will be the base provider.
            LegalKeySizesValue = s_legalKeySizes;

            // Since the CSP only supports a CFB feedback of 8, make that the default
            FeedbackSizeValue = 8;
        }
 public DESCryptoServiceProvider()
 {
     if (!Utils.HasAlgorithm(0x6601, 0))
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgorithmNotAvailable"));
     }
     base.FeedbackSizeValue = 8;
 }
예제 #3
0
 public RC2CryptoServiceProvider()
 {
     if (CryptoConfig.AllowOnlyFipsAlgorithms)
     {
         throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
     }
     if (!Utils.HasAlgorithm(0x6602, 0))
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgorithmNotAvailable"));
     }
     base.LegalKeySizesValue = s_legalKeySizes;
     base.FeedbackSizeValue  = 8;
 }
예제 #4
0
 public RC2CryptoServiceProvider()
 {
     if (CryptoConfig.AllowOnlyFipsAlgorithms && AppContextSwitches.UseLegacyFipsThrow)
     {
         throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
     }
     if (!Utils.HasAlgorithm(26114, 0))
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgorithmNotAvailable"));
     }
     this.LegalKeySizesValue = RC2CryptoServiceProvider.s_legalKeySizes;
     this.FeedbackSizeValue  = 8;
 }
        [System.Security.SecuritySafeCritical]  // auto-generated
        public RC2CryptoServiceProvider()
        {
            if (CryptoConfig.AllowOnlyFipsAlgorithms)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
            }
            Contract.EndContractBlock();
            if (!Utils.HasAlgorithm(Constants.CALG_RC2, 0))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgorithmNotAvailable"));
            }

            // Acquire a Type 1 provider. This will be the Enhanced provider if available, otherwise
            // it will be the base provider.
            LegalKeySizesValue = s_legalKeySizes;

            // Since the CSP only supports a CFB feedback of 8, make that the default
            FeedbackSizeValue = 8;
        }
예제 #6
0
        private ICryptoTransform _NewEncryptor(byte[] rgbKey, CipherMode mode, byte[] rgbIV, int effectiveKeySize, int feedbackSize, CryptoAPITransformMode encryptMode)
        {
            int index = 0;

            int[]    rgArgIds    = new int[10];
            object[] rgArgValues = new object[10];
            if (mode == CipherMode.OFB)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_OFBNotSupported"));
            }
            if ((mode == CipherMode.CFB) && (feedbackSize != 8))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_CFBSizeNotSupported"));
            }
            if (rgbKey == null)
            {
                rgbKey = new byte[base.KeySizeValue / 8];
                Utils.StaticRandomNumberGenerator.GetBytes(rgbKey);
            }
            int bitLength = rgbKey.Length * 8;

            if (!base.ValidKeySize(bitLength))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }
            rgArgIds[index] = 0x13;
            if (base.EffectiveKeySizeValue == 0)
            {
                rgArgValues[index] = bitLength;
            }
            else
            {
                rgArgValues[index] = effectiveKeySize;
            }
            index++;
            if (mode != CipherMode.CBC)
            {
                rgArgIds[index]    = 4;
                rgArgValues[index] = mode;
                index++;
            }
            if (mode != CipherMode.ECB)
            {
                if (rgbIV == null)
                {
                    rgbIV = new byte[8];
                    Utils.StaticRandomNumberGenerator.GetBytes(rgbIV);
                }
                if (rgbIV.Length < 8)
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidIVSize"));
                }
                rgArgIds[index]    = 1;
                rgArgValues[index] = rgbIV;
                index++;
            }
            if ((mode == CipherMode.OFB) || (mode == CipherMode.CFB))
            {
                rgArgIds[index]    = 5;
                rgArgValues[index] = feedbackSize;
                index++;
            }
            if (!Utils.HasAlgorithm(0x6602, bitLength))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgKeySizeNotAvailable", new object[] { bitLength }));
            }
            return(new CryptoAPITransform(0x6602, index, rgArgIds, rgArgValues, rgbKey, base.PaddingValue, mode, base.BlockSizeValue, feedbackSize, this.m_use40bitSalt, encryptMode));
        }
        [System.Security.SecurityCritical]  // auto-generated
        private ICryptoTransform _NewEncryptor(byte[] rgbKey, CipherMode mode, byte[] rgbIV,
                                               int effectiveKeySize, int feedbackSize, CryptoAPITransformMode encryptMode)
        {
            int cArgs = 0;

            int[]    rgArgIds    = new int[10];
            Object[] rgArgValues = new Object[10];

            // Check for bad values
            // 1) we don't support OFB mode in RC2_CSP
            if (mode == CipherMode.OFB)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_OFBNotSupported"));
            }
            // 2) we only support CFB with a feedback size of 8 bits
            if ((mode == CipherMode.CFB) && (feedbackSize != 8))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_CFBSizeNotSupported"));
            }

            if (rgbKey == null)
            {
                rgbKey = new byte[KeySizeValue / 8];
                Utils.StaticRandomNumberGenerator.GetBytes(rgbKey);
            }

            // Check the rgbKey size
            int keySizeValue = rgbKey.Length * 8;

            if (!ValidKeySize(keySizeValue))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }

            // Deal with effective key length questions
            rgArgIds[cArgs] = Constants.KP_EFFECTIVE_KEYLEN;
            if (EffectiveKeySizeValue == 0)
            {
                rgArgValues[cArgs] = keySizeValue;
            }
            else
            {
                rgArgValues[cArgs] = effectiveKeySize;
            }
            cArgs += 1;

            // Set the mode for the encryptor (defaults to CBC)
            if (mode != CipherMode.CBC)
            {
                rgArgIds[cArgs]    = Constants.KP_MODE;
                rgArgValues[cArgs] = mode;
                cArgs += 1;
            }

            // If not ECB mode -- pass in an IV
            if (mode != CipherMode.ECB)
            {
                if (rgbIV == null)
                {
                    rgbIV = new byte[8];
                    Utils.StaticRandomNumberGenerator.GetBytes(rgbIV);
                }

                //
                // We truncate IV's that are longer than the block size to 8 bytes : this is
                // done to maintain backward compatibility with the behavior shipped in V1.x.
                // The call to set the IV in CryptoAPI will ignore any bytes after the first 8
                // bytes. We'll still reject IV's that are shorter than the block size though.
                //
                if (rgbIV.Length < 8)
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidIVSize"));
                }

                rgArgIds[cArgs]    = Constants.KP_IV;
                rgArgValues[cArgs] = rgbIV;
                cArgs += 1;
            }

            // If doing OFB or CFB, then we need to set the feed back loop size
            if ((mode == CipherMode.OFB) || (mode == CipherMode.CFB))
            {
                rgArgIds[cArgs]    = Constants.KP_MODE_BITS;
                rgArgValues[cArgs] = feedbackSize;
                cArgs += 1;
            }

            if (!Utils.HasAlgorithm(Constants.CALG_RC2, keySizeValue))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgKeySizeNotAvailable", keySizeValue));
            }

            //  Create the encryptor/decryptor object
            return(new CryptoAPITransform(Constants.CALG_RC2, cArgs, rgArgIds,
                                          rgArgValues, rgbKey, PaddingValue,
                                          mode, BlockSizeValue, feedbackSize, m_use40bitSalt,
                                          encryptMode));
        }
        private ICryptoTransform _NewEncryptor(byte[] rgbKey, CipherMode mode, byte[] rgbIV, int effectiveKeySize, int feedbackSize, CryptoAPITransformMode encryptMode)
        {
            int index = 0;

            int[]    rgArgIds    = new int[10];
            object[] rgArgValues = new object[10];
            if (mode == CipherMode.OFB)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_OFBNotSupported"));
            }
            if (mode == CipherMode.CFB && feedbackSize != 8)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_CFBSizeNotSupported"));
            }
            if (rgbKey == null)
            {
                rgbKey = new byte[this.KeySizeValue / 8];
                Utils.StaticRandomNumberGenerator.GetBytes(rgbKey);
            }
            int num = rgbKey.Length * 8;

            if (!this.ValidKeySize(num))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }
            rgArgIds[index]    = 19;
            rgArgValues[index] = this.EffectiveKeySizeValue != 0 ? (object)effectiveKeySize : (object)num;
            int cArgs = index + 1;

            if (mode != CipherMode.CBC)
            {
                rgArgIds[cArgs]    = 4;
                rgArgValues[cArgs] = (object)mode;
                ++cArgs;
            }
            if (mode != CipherMode.ECB)
            {
                if (rgbIV == null)
                {
                    rgbIV = new byte[8];
                    Utils.StaticRandomNumberGenerator.GetBytes(rgbIV);
                }
                if (rgbIV.Length < 8)
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidIVSize"));
                }
                rgArgIds[cArgs]    = 1;
                rgArgValues[cArgs] = (object)rgbIV;
                ++cArgs;
            }
            if (mode == CipherMode.OFB || mode == CipherMode.CFB)
            {
                rgArgIds[cArgs]    = 5;
                rgArgValues[cArgs] = (object)feedbackSize;
                ++cArgs;
            }
            if (!Utils.HasAlgorithm(26114, num))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgKeySizeNotAvailable", (object)num));
            }
            return((ICryptoTransform) new CryptoAPITransform(26114, cArgs, rgArgIds, rgArgValues, rgbKey, this.PaddingValue, mode, this.BlockSizeValue, feedbackSize, this.m_use40bitSalt, encryptMode));
        }
예제 #9
0
        private ICryptoTransform _NewEncryptor(byte[] rgbKey, CipherMode mode, byte[] rgbIV, int effectiveKeySize, int feedbackSize, CryptoAPITransformMode encryptMode)
        {
            int num = 0;

            int[]    array  = new int[10];
            object[] array2 = new object[10];
            if (mode == CipherMode.OFB)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_OFBNotSupported"));
            }
            if (mode == CipherMode.CFB && feedbackSize != 8)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_CFBSizeNotSupported"));
            }
            if (rgbKey == null)
            {
                rgbKey = new byte[this.KeySizeValue / 8];
                Utils.StaticRandomNumberGenerator.GetBytes(rgbKey);
            }
            int num2 = rgbKey.Length * 8;

            if (!base.ValidKeySize(num2))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }
            array[num] = 19;
            if (this.EffectiveKeySizeValue == 0)
            {
                array2[num] = num2;
            }
            else
            {
                array2[num] = effectiveKeySize;
            }
            num++;
            if (mode != CipherMode.CBC)
            {
                array[num]  = 4;
                array2[num] = mode;
                num++;
            }
            if (mode != CipherMode.ECB)
            {
                if (rgbIV == null)
                {
                    rgbIV = new byte[8];
                    Utils.StaticRandomNumberGenerator.GetBytes(rgbIV);
                }
                if (rgbIV.Length < 8)
                {
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidIVSize"));
                }
                array[num]  = 1;
                array2[num] = rgbIV;
                num++;
            }
            if (mode == CipherMode.OFB || mode == CipherMode.CFB)
            {
                array[num]  = 5;
                array2[num] = feedbackSize;
                num++;
            }
            if (!Utils.HasAlgorithm(26114, num2))
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_AlgKeySizeNotAvailable", new object[]
                {
                    num2
                }));
            }
            return(new CryptoAPITransform(26114, num, array, array2, rgbKey, this.PaddingValue, mode, this.BlockSizeValue, feedbackSize, this.m_use40bitSalt, encryptMode));
        }