private static ICryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, int effectiveKeyLength, byte[]?iv, int blockSize, int feedbackSize, int paddingSize, bool encrypting) { // The algorithm pointer is a static pointer, so not having any cleanup code is correct. IntPtr algorithm; switch (cipherMode) { case CipherMode.CBC: algorithm = Interop.Crypto.EvpRC2Cbc(); break; case CipherMode.ECB: algorithm = Interop.Crypto.EvpRC2Ecb(); break; default: throw new NotSupportedException(); } BasicSymmetricCipher cipher = new OpenSslCipher(algorithm, cipherMode, blockSize, paddingSize, key, effectiveKeyLength, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private ICryptoTransform CreateCryptoTransformCore(Func <CngKey> cngKeyFactory, byte[] iv, bool encrypting) { int blockSizeInBytes = _outer.BlockSize.BitSizeToByteSize(); BasicSymmetricCipher cipher = new BasicSymmetricCipherCng(cngKeyFactory, _outer.Mode, blockSizeInBytes, iv, encrypting); return(UniversalCryptoTransform.Create(_outer.Padding, cipher, encrypting)); }
private ICryptoTransform CreatePersistedCryptoTransformCore(Func <CngKey> cngKeyFactory, byte[] iv, bool encrypting) { // note: iv is guaranteed to be cloned before this method, so no need to clone it again int blockSizeInBytes = _outer.BlockSize.BitSizeToByteSize(); BasicSymmetricCipher cipher = new BasicSymmetricCipherNCrypt(cngKeyFactory, _outer.Mode, blockSizeInBytes, iv, encrypting); return(UniversalCryptoTransform.Create(_outer.Padding, cipher, encrypting)); }
private ICryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[] iv, int blockSize, bool encrypting) { BasicSymmetricCipher cipher = new TripleDesOpenSslCipher(cipherMode, blockSize, key, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private static ICryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[] iv, int blockSize, bool encrypting) { SafeAlgorithmHandle algorithm = DesBCryptModes.GetSharedHandle(cipherMode); BasicSymmetricCipher cipher = new BasicSymmetricCipherBCrypt(algorithm, cipherMode, blockSize, key, false, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private static ICryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[] iv, int blockSize, bool encrypting) { SafeAlgorithmHandle algorithm = GetCipherAlgorithm(cipherMode); BasicSymmetricCipher cipher = new CngCipher(algorithm, cipherMode, blockSize, key, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private ICryptoTransform CreateEphemeralCryptoTransformCore(byte[] key, byte[] iv, bool encrypting) { int blockSizeInBytes = _outer.BlockSize.BitSizeToByteSize(); SafeAlgorithmHandle algorithmModeHandle = _outer.GetEphemeralModeHandle(); BasicSymmetricCipher cipher = new BasicSymmetricCipherBCrypt( algorithmModeHandle, _outer.Mode, blockSizeInBytes, key, iv, encrypting); return(UniversalCryptoTransform.Create(_outer.Padding, cipher, encrypting)); }
private static ICryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[] iv, int blockSize, bool encrypting) { // The algorithm pointer is a static pointer, so not having any cleanup code is correct. IntPtr algorithm = GetAlgorithm(key.Length * 8, cipherMode); BasicSymmetricCipher cipher = new OpenSslCipher(algorithm, cipherMode, blockSize, key, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private static ICryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, int effectiveKeyLength, byte[]?iv, int blockSize, bool encrypting) { using (SafeAlgorithmHandle algorithm = RC2BCryptModes.GetHandle(cipherMode, effectiveKeyLength)) { // The BasicSymmetricCipherBCrypt ctor will increase algorithm reference count and take ownership. BasicSymmetricCipher cipher = new BasicSymmetricCipherBCrypt(algorithm, cipherMode, blockSize, key, true, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); } }
private UniversalCryptoTransform CreatePersistedCryptoTransformCore(Func <CngKey> cngKeyFactory, byte[]?iv, bool encrypting, PaddingMode padding, CipherMode mode) { // note: iv is guaranteed to be cloned before this method, so no need to clone it again int blockSizeInBytes = _outer.BlockSize.BitSizeToByteSize(); int feedbackSizeInBytes = _outer.FeedbackSize; BasicSymmetricCipher cipher = new BasicSymmetricCipherNCrypt( cngKeyFactory, mode, blockSizeInBytes, iv, encrypting, feedbackSizeInBytes, _outer.GetPaddingSize(mode, _outer.FeedbackSize)); return(UniversalCryptoTransform.Create(padding, cipher, encrypting)); }
private UniversalCryptoTransform CreateEphemeralCryptoTransformCore(byte[] key, byte[]?iv, bool encrypting, PaddingMode padding, CipherMode mode) { int blockSizeInBytes = _outer.BlockSize.BitSizeToByteSize(); SafeAlgorithmHandle algorithmModeHandle = _outer.GetEphemeralModeHandle(mode); BasicSymmetricCipher cipher = new BasicSymmetricCipherBCrypt( algorithmModeHandle, mode, blockSizeInBytes, _outer.GetPaddingSize(mode, _outer.FeedbackSize), key, ownsParentHandle: false, iv, encrypting); return(UniversalCryptoTransform.Create(padding, cipher, encrypting)); }
private static ICryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[] iv, int blockSize, bool encrypting) { BasicSymmetricCipher cipher = new AppleCCCryptor( Interop.AppleCrypto.PAL_SymmetricAlgorithm.TripleDES, cipherMode, blockSize, key, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private static UniversalCryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[]?iv, int blockSize, int feedbackSize, int paddingSize, bool encrypting) { // The algorithm pointer is a static pointer, so not having any cleanup code is correct. IntPtr algorithm = GetAlgorithm(cipherMode, feedbackSize); Interop.Crypto.EnsureLegacyAlgorithmsRegistered(); BasicSymmetricCipher cipher = new OpenSslCipher(algorithm, cipherMode, blockSize, paddingSize, key, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private static UniversalCryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[]?iv, int blockSize, int feedbackSize, int paddingSize, bool encrypting) { // The algorithm pointer is a static pointer, so not having any cleanup code is correct. IntPtr algorithm = IntPtr.Zero; switch (cipherMode) { case CipherMode.CBC: algorithm = Interop.Crypto.EvpDesCbc(); break; case CipherMode.ECB: algorithm = Interop.Crypto.EvpDesEcb(); break; case CipherMode.CFB: Debug.Assert(feedbackSize == 1, "DES with CFB should have FeedbackSize set to 1"); algorithm = Interop.Crypto.EvpDesCfb8(); break; default: throw new NotSupportedException(); } Interop.Crypto.EnsureLegacyAlgorithmsRegistered(); BasicSymmetricCipher cipher = new OpenSslCipher(algorithm, cipherMode, blockSize, paddingSize, key, 0, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private static UniversalCryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[]?iv, int blockSize, int feedbackSizeInBytes, int paddingSize, bool encrypting) { BasicSymmetricCipher cipher = new AppleCCCryptor( Interop.AppleCrypto.PAL_SymmetricAlgorithm.RC2, cipherMode, blockSize, key, iv, encrypting, feedbackSizeInBytes, paddingSize); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }
private static UniversalCryptoTransform CreateTransformCore( CipherMode cipherMode, PaddingMode paddingMode, byte[] key, byte[]?iv, int blockSize, int paddingSize, int feedbackSize, bool encrypting) { // The algorithm pointer is a static pointer, so not having any cleanup code is correct. IntPtr algorithm; switch ((cipherMode, feedbackSize)) { case (CipherMode.CBC, _): algorithm = Interop.Crypto.EvpDes3Cbc(); break; case (CipherMode.ECB, _): algorithm = Interop.Crypto.EvpDes3Ecb(); break; case (CipherMode.CFB, 1): algorithm = Interop.Crypto.EvpDes3Cfb8(); break; case (CipherMode.CFB, 8): algorithm = Interop.Crypto.EvpDes3Cfb64(); break; default: throw new NotSupportedException(); } BasicSymmetricCipher cipher = new OpenSslCipher(algorithm, cipherMode, blockSize, paddingSize, key, 0, iv, encrypting); return(UniversalCryptoTransform.Create(paddingMode, cipher, encrypting)); }