Exemple #1
0
		public CryptoStream (Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
		{
			if ((mode == CryptoStreamMode.Read) && (!stream.CanRead)) {
				throw new ArgumentException (
					Locale.GetText ("Can't read on stream"));
			}
			if ((mode == CryptoStreamMode.Write) && (!stream.CanWrite)) {
				throw new ArgumentException (
					Locale.GetText ("Can't write on stream"));
			}
			_stream = stream;
			_transform = transform;
			_mode = mode;
			_disposed = false;
			if (transform != null) {
				if (mode == CryptoStreamMode.Read) {
					_currentBlock = new byte [transform.InputBlockSize];
					_workingBlock = new byte [transform.InputBlockSize];
				}
				else if (mode == CryptoStreamMode.Write) {
					_currentBlock = new byte [transform.OutputBlockSize];
					_workingBlock = new byte [transform.OutputBlockSize];
				}
			}
		}
        public InteractiveCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode, int bufferSizeInBlocks)
            : base(stream)
        {
            if (bufferSizeInBlocks < 0)
            {
                throw new ArgumentOutOfRangeException("bufferSizeInBlocks", bufferSizeInBlocks, "BufferSize can't be less than 0");
            }

            if (bufferSizeInBlocks > 255)
            {
                bufferSizeInBlocks = 255;
            }

            this.mode = mode;

            this.transform = transform;

            this.writeBuffer = new byte[2 + transform.InputBlockSize * bufferSizeInBlocks];
            this.writeBlockBuffer = new byte[transform.OutputBlockSize];

            this.readPreBuffer = new byte[transform.OutputBlockSize * 5];
            this.readBuffer = new byte[transform.InputBlockSize * 5];

            this.writeBufferCount = 2;
            this.readBufferCount = 0;
            this.readBufferIndex = 0;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Streams.NonClosingHashStream"/> class.
        /// </summary>
        /// <param name='stream'>
        /// Wrapped stream.
        /// </param>
        /// <param name='hashAlg'>
        /// Hash algorithm, which should be used for hash calculations.
        /// </param>
        /// <param name='mode'>
        /// Setting the mode, when hashing should be executed. On Read will transform the hash while reading, or Write mode for transforming while writing.
        /// </param>
        public NonClosingHashStream(Stream stream, HashAlgorithm hashAlg, CryptoStreamMode mode) : base(stream) {
            if (hashAlg == null) {
                throw new ArgumentNullException("hashAlg");
            }

            this.hashAlg = hashAlg;
            this.mode = mode;
        }
Exemple #4
0
 public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode mode) : base(stream, transform, mode)
 {
     this._stream = stream;
     this._transform = transform;
     this._slideBuffer = new byte[0x400];
     this._blockAndAuth = 0x1a;
     if (mode != CryptoStreamMode.Read)
     {
         throw new Exception("ZipAESStream only for read");
     }
 }
Exemple #5
0
 public OfbStream(Stream parent, SymmetricAlgorithm algo, CryptoStreamMode mode)
 {
     if (algo.Mode != CipherMode.CBC)
         algo.Mode = CipherMode.CBC;
     if (algo.Padding != PaddingMode.None)
         algo.Padding = PaddingMode.None;
     _parent = parent;
     _cbcStream = new CryptoStream(new ZeroStream(), algo.CreateEncryptor(), CryptoStreamMode.Read);
     _mode = mode;
     _keyStreamBuffer = new byte[algo.BlockSize * Blocks];
     _readWriteBuffer = new byte[_keyStreamBuffer.Length];
 }
Exemple #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="stream">The stream on which to perform the cryptographic transformation.</param>
        /// <param name="transform">Instance of ZipAESTransform</param>
        /// <param name="mode">Read or Write</param>
        public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode mode)
            : base(stream, transform, mode)
        {
            _stream = stream;
            _transform = transform;
            _slideBuffer = new byte[1024];

            _blockAndAuth = CRYPTO_BLOCK_SIZE + AUTH_CODE_LENGTH;

            // mode:
            //  CryptoStreamMode.Read means we read from "stream" and pass decrypted to our Read() method.
            //  Write bypasses this stream and uses the Transform directly.
            if (mode != CryptoStreamMode.Read) throw new Exception("ZipAESStream only for read");
        }
	// Constructor.
	public CryptoStream(Stream stream, ICryptoTransform transform,
						CryptoStreamMode mode)
			{
				this.stream = stream;
				this.transform = transform;
				this.mode = mode;
				this.flushFinal = false;
				if(mode == CryptoStreamMode.Read)
				{
					if(!(stream.CanRead))
					{
						throw new NotSupportedException
							(_("IO_NotSupp_Read"));
					}
				}
				else if(mode == CryptoStreamMode.Write)
				{
					if(!(stream.CanWrite))
					{
						throw new NotSupportedException
							(_("IO_NotSupp_Write"));
					}
				}
				else
				{
					throw new NotSupportedException
						(_("Crypto_InvalidStreamMode"));
				}
				inBlockSize = transform.InputBlockSize;
				outBlockSize = transform.OutputBlockSize;
				if(transform.CanTransformMultipleBlocks)
				{
					inBufferSize = 1024 - (1024 % inBlockSize);
					outBufferSize =
						(inBufferSize / inBlockSize) * outBlockSize;
				}
				else
				{
					// We need at least two blocks in the input buffer to
					// process padding blocks at the end of the stream.
					inBufferSize = transform.InputBlockSize * 2;
					outBufferSize = transform.OutputBlockSize;
				}
				inBuffer = new byte [inBufferSize];
				outBuffer = new byte [outBufferSize];
				inBufferPosn = 0;
				outBufferPosn = 0;
				sawEOF = false;
			}
        Stream ICryptoStreamProvider.GetDecryptStream(Stream stream, string keyId, CryptoStreamMode streamMode)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            keyId = keyId ?? _defaultKeyId;

            SymmetricKey key;
            if (!_keyProvider.TryGetKey(keyId, out key))
                throw new SerializationException("Encryption Key not found: " + keyId);

            ICryptoTransform encryptor = CreateDecryptor(key.Key, key.IV);

            return new DisposingCryptoStream(stream, encryptor, streamMode);
        }
Exemple #9
0
        // Constructors

        public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode) {
            _stream = stream;
            _transformMode = mode;
            _Transform = transform;
            switch (_transformMode) {
            case CryptoStreamMode.Read:
                if (!(_stream.CanRead)) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable"),"stream");
                _canRead = true;
                break;
            case CryptoStreamMode.Write:
                if (!(_stream.CanWrite)) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotWritable"),"stream");
                _canWrite = true;
                break;
            default:
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"));
            }
            InitializeBuffer();
        }
        public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode, bool leaveOpen)
        {

            _stream = stream;
            _transformMode = mode;
            _transform = transform;
            _leaveOpen = leaveOpen;
            switch (_transformMode)
            {
                case CryptoStreamMode.Read:
                    if (!(_stream.CanRead)) throw new ArgumentException(SR.Format(SR.Argument_StreamNotReadable, nameof(stream)));
                    _canRead = true;
                    break;
                case CryptoStreamMode.Write:
                    if (!(_stream.CanWrite)) throw new ArgumentException(SR.Format(SR.Argument_StreamNotWritable, nameof(stream)));
                    _canWrite = true;
                    break;
                default:
                    throw new ArgumentException(SR.Argument_InvalidValue);
            }
            InitializeBuffer();
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CryptoStream"/> class.
        /// </summary>
        /// <param name="stream">The stream to write to or read from.</param>
        /// <param name="transform">The cryptographic operation to use for transforming data.</param>
        /// <param name="mode">The mode of operation.</param>
        public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
        {
            Requires.NotNull(stream, "stream");
            Requires.NotNull(transform, "transform");

            if (mode == CryptoStreamMode.Read)
            {
                Requires.Argument(stream.CanRead, "stream", "Stream is not readable.");
            }
            else if (mode == CryptoStreamMode.Write)
            {
                Requires.Argument(stream.CanWrite, "stream", "Stream is not writeable.");
            }
            else
            {
                Requires.That(false, "mode", "Unsupported mode.");
            }

            this.chainedStream = stream;
            this.transform = transform;
            this.mode = mode;
            this.inputBuffer = new byte[transform.InputBlockSize];
            this.outputBuffer = new byte[transform.OutputBlockSize];
        }
 public CryptoStream (System.IO.Stream stream, ICryptoTransform transform, CryptoStreamMode mode) {
   return default(CryptoStream);
 }
Exemple #13
0
 public MinimalCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode) : base(stream, transform, mode)
 {
 }
 public SeekableCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
     _stream = stream;
 }
Exemple #15
0
        public override CryptoStreamBase Initialize(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
        {
            _cryptoTransform = new CryptoTransformUnwrapper(transform);

            System.Security.Cryptography.CryptoStreamMode streamMode;
            switch (mode)
            {
            case CryptoStreamMode.Read:
                streamMode = System.Security.Cryptography.CryptoStreamMode.Read;
                break;

            case CryptoStreamMode.Write:
                streamMode = System.Security.Cryptography.CryptoStreamMode.Write;
                break;

            default:
                streamMode = (System.Security.Cryptography.CryptoStreamMode)mode;
                break;
            }

            _cryptoStream = new System.Security.Cryptography.CryptoStream(stream, _cryptoTransform, streamMode);
            return(this);
        }
Exemple #16
0
 /// <summary>
 /// Creates new instance using 256 bit AES in CBC mode.
 /// </summary>
 /// <param name="stream">The stream on which to perform the cryptographic transformation.</param>
 /// <param name="password">Password used for key and IV derivation.</param>
 /// <param name="streamMode">The cryptographic transformation that is to be performed on the stream.</param>
 /// <exception cref="System.ArgumentNullException">Stream cannot be null. -or- Password cannot be null.</exception>
 /// <exception cref="System.ArgumentException">Stream mode must be either Read or Write. -or- Stream is not readable. -or- Stream is not writable.</exception>
 /// <exception cref="System.IO.InvalidDataException">Unexpected end of stream. -or- Salted stream expected.</exception>
 public OpenSslAesStream(Stream stream, Byte[] password, CryptoStreamMode streamMode)
     : this(stream, password, streamMode, 256, CipherMode.CBC)
 {
 }
 public CryptoStreamBase Create(Stream stream, ICryptoTransform cryptoTransform, CryptoStreamMode cryptoStreamMode)
 {
     return _cryptoStreamFactory.Create(stream, cryptoTransform, cryptoStreamMode);
 }
 protected abstract Stream CreateCryptoStream(Stream target, ICryptoTransform transform, CryptoStreamMode mode);
Exemple #19
0
 /// <summary> Provides reading and writing to a stream of base-64 characters. </summary>
 public Base64Stream(Stream stream, CryptoStreamMode mode)
     : base(stream, new Transform(mode), mode)
 {
 }
 public ReturnableCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode, IDisposable algorithom)
     : base(stream, transform, mode)
 {
     _transform  = transform;
     _algorithom = algorithom;
 }
        public static bool FileEncryptDES(string filePath, string password)
        {
            bool   result;
            string fileEncryptedPath = filePath + ".crp";

            try
            {
                if (File.Exists(filePath))
                {
                    byte[] buffer        = File.ReadAllBytes(filePath);
                    byte[] passwordBytes = Encoding.UTF8.GetBytes(password);

                    // Set encryption settings -- Use password for both key and init. vector
                    DESCryptoServiceProvider provider  = new DESCryptoServiceProvider();
                    ICryptoTransform         transform = provider.CreateEncryptor(passwordBytes, passwordBytes);
                    CryptoStreamMode         mode      = CryptoStreamMode.Write;

                    // Set up streams and encrypt
                    MemoryStream memStream    = new MemoryStream();
                    CryptoStream cryptoStream = new CryptoStream(memStream, transform, mode);
                    cryptoStream.Write(buffer, 0, buffer.Length);
                    cryptoStream.FlushFinalBlock();

                    // Read the encrypted message from the memory stream
                    byte[] encryptedFile = new byte[memStream.Length];
                    memStream.Position = 0;
                    memStream.Read(encryptedFile, 0, encryptedFile.Length);

                    File.WriteAllBytes(fileEncryptedPath, encryptedFile);

                    if (File.Exists(fileEncryptedPath))
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    result = false;
                }

                if (result)
                {
                    Sistem.WriteLog(Sistem.GetLogTag(Sistem.EnumLogTags.CRYPTOGRAPHY), "Create File Encrypt DES in " + fileEncryptedPath, false, false, true, classColor);
                }
                else
                {
                    Sistem.WriteLog(Sistem.GetLogTag(Sistem.EnumLogTags.CRYPTOGRAPHY), "File  " + filePath + " does not exist", false, false, true, classColor);
                }
            }
            catch (Exception ex)
            {
                Sistem.WriteLog(ex, Sistem.GetLogTag(Sistem.EnumLogTags.CRYPTOGRAPHYCERROR) + "FileEncryptDES(string filePath, string password)", true);
                error += ex.Message + "\n";
                result = false;
            }
            return(result);
        }
Exemple #22
0
 public DisposingCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
     _stream    = stream;
     _transform = transform;
 }
Exemple #23
0
        private static byte[] DoCryptoTransform(String keyFileName, byte[] sourceData, CreateTransform transformFunc, CryptoStreamMode mode)
        {
#if CRYPTOTRIAL
            using (MemoryStream mstr = new MemoryStream())
            {
                using (var provider = CreateProvider(keyFileName))
                {
                    using (var cryptoStream = new CryptoStream(mstr, transformFunc(provider), mode))
                    {
                        cryptoStream.Write(sourceData, 0, sourceData.Length);
                    }
                }
                return(mstr.ToArray());
            }
#else
            return(sourceData);
#endif
        }
Exemple #24
0
        /// <summary>
        /// Creates new instance.
        /// </summary>
        /// <param name="stream">The stream on which to perform the cryptographic transformation.</param>
        /// <param name="password">Password used for key and IV derivation.</param>
        /// <param name="streamMode">The cryptographic transformation that is to be performed on the stream.</param>
        /// <param name="keySize">Size of key.</param>
        /// <param name="cipherMode">The mode for operation of the symmetric algorithm.</param>
        /// <exception cref="System.ArgumentNullException">Stream cannot be null. -or- Password cannot be null.</exception>
        /// <exception cref="System.ArgumentException">Stream mode must be either Read or Write. -or- Stream is not readable. -or- Stream is not writable. -or- Key size mode must be either 128, 192 or 256 bits. -or- Cipher mode must be either CBC or OFB.</exception>
        /// <exception cref="System.IO.InvalidDataException">Unexpected end of stream. -or- Salted stream expected.</exception>
        public OpenSslAesStream(Stream stream, Byte[] password, CryptoStreamMode streamMode, Int32 keySize, CipherMode cipherMode)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream", "Stream cannot be null.");
            }
            if (password == null)
            {
                throw new ArgumentNullException("password", "Password cannot be null.");
            }
            if ((streamMode != CryptoStreamMode.Read) && (streamMode != CryptoStreamMode.Write))
            {
                throw new ArgumentException("Stream mode must be either Read or Write.", "streamMode");
            }
            if ((streamMode == CryptoStreamMode.Read) && (stream.CanRead == false))
            {
                throw new ArgumentException("Stream is not readable.", "stream");
            }
            if ((streamMode == CryptoStreamMode.Write) && (stream.CanWrite == false))
            {
                throw new ArgumentException("Stream is not writable.", "stream");
            }
            if ((keySize != 128) && (keySize != 192) && (keySize != 256))
            {
                throw new ArgumentException("Key size mode must be either 128, 192 or 256 bits.", "keySize");
            }
            if ((cipherMode != CipherMode.CBC) && (cipherMode != CipherMode.ECB))
            {
                throw new ArgumentException("Cipher mode must be either CBC or OFB.", "cipherMode");
            }

            if (streamMode == CryptoStreamMode.Read)
            {
                var buffer = new byte[16];
                var len    = stream.Read(buffer, 0, 16);
                if (len < 16)
                {
                    throw new InvalidDataException("Unexpected end of stream.");
                }
                for (int i = 0; i < 8; i++)
                {
                    if (buffer[i] != SaltedTextCache[i])
                    {
                        throw new InvalidDataException("Salted stream expected.");
                    }
                }
                var salt = new byte[8];
                Buffer.BlockCopy(buffer, 8, salt, 0, 8);

                byte[] key, iv;
                GenerateKeyAndIV(password, salt, keySize, 128, out key, out iv);
                using (var aes = new RijndaelManaged()) {
                    aes.BlockSize  = 128;
                    aes.KeySize    = keySize;
                    aes.Mode       = cipherMode;
                    aes.Padding    = PaddingMode.PKCS7;
                    this.Transform = aes.CreateDecryptor(key, iv);
                    this.Stream    = new CryptoStream(stream, this.Transform, CryptoStreamMode.Read);
                }
            }
            else
            {
                var salt = new byte[8];
                Rnd.GetBytes(salt);
                stream.Write(SaltedTextCache, 0, 8);
                stream.Write(salt, 0, 8);

                byte[] key, iv;
                GenerateKeyAndIV(password, salt, keySize, 128, out key, out iv);
                using (var aes = new RijndaelManaged()) {
                    aes.BlockSize  = 128;
                    aes.KeySize    = keySize;
                    aes.Mode       = cipherMode;
                    aes.Padding    = PaddingMode.PKCS7;
                    this.Transform = aes.CreateEncryptor(key, iv);
                    this.Stream    = new CryptoStream(stream, this.Transform, CryptoStreamMode.Write);
                }
            }
        }
Exemple #25
0
 /// <summary>
 /// Creates new instance.
 /// </summary>
 /// <param name="stream">The stream on which to perform the cryptographic transformation.</param>
 /// <param name="password">Password used for key and IV derivation. UTF-8 encoding is assumed.</param>
 /// <param name="streamMode">The cryptographic transformation that is to be performed on the stream.</param>
 /// <param name="keySize">Size of key.</param>
 /// <param name="cipherMode">The mode for operation of the symmetric algorithm.</param>
 /// <exception cref="System.ArgumentNullException">Stream cannot be null. -or- Password cannot be null.</exception>
 /// <exception cref="System.ArgumentException">Stream mode must be either Read or Write. -or- Stream is not readable. -or- Stream is not writable. -or- Key size mode must be either 128, 192 or 256 bits. -or- Cipher mode must be either CBC or OFB.</exception>
 /// <exception cref="System.IO.InvalidDataException">Unexpected end of stream. -or- Salted stream expected.</exception>
 public OpenSslAesStream(Stream stream, String password, CryptoStreamMode streamMode, Int32 keySize, CipherMode cipherMode)
     : this(stream, UTF8Encoding.UTF8.GetBytes(password), streamMode, keySize, cipherMode)
 {
 }
 public InteractiveCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : this(stream, transform, mode, 255)
 {
 }
 public PwdTdsCryptoStream(System.IO.Stream Stream, CryptoStreamMode Mode, string Password)
     : this(Stream, CreateTripleDESTransform(Mode, Password), Mode)
 {
 }
Exemple #28
0
 /// <summary> Provides a crypto-transform used to read/write to a stream of base-64 characters. </summary>
 public Transform(CryptoStreamMode mode)
 {
     _mode = mode;
 }
Exemple #29
0
        /// <summary>
        /// Creates a CryptoStream chain of transforms.
        /// </summary>
        /// <param name="stream">The ultimate stream to be read from or written to.</param>
        /// <param name="cryptoStreamMode">Whether to prepare for read or write operations to trigger the operations.</param>
        /// <param name="transforms">The transforms to apply.</param>
        /// <returns>The start of the chain of CryptoStreams.</returns>
        private static CryptoStream Chain(Stream stream, CryptoStreamMode cryptoStreamMode, params ICryptoTransform[] transforms)
        {
            Requires.NotNull(stream, "stream");
            Requires.NotNullOrEmpty(transforms, "transforms");

            if (cryptoStreamMode == CryptoStreamMode.Write)
            {
                // Arrange the transforming streams in this fashion:
                // T1 -> T2 -> stream
                // Which means we need recursion to define:
                // CS1(CS2(stream))
                using (IEnumerator<ICryptoTransform> transformsEnumerator = transforms.Cast<ICryptoTransform>().GetEnumerator())
                {
                    return (CryptoStream)ChainWrite(stream, transformsEnumerator);
                }
            }
            else
            {
                // Arrange the transforming streams in this fashion:
                // stream -> T1 -> T2
                // Which means we need iteration to define:
                // CS2(CS1(stream))
                foreach (var transform in transforms)
                {
                    stream = new CryptoStream(stream, transform, CryptoStreamMode.Read);
                }

                return (CryptoStream)stream;
            }
        }
Exemple #30
0
 public WakeariStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
     LastBytes = new byte[20];
 }
Exemple #31
0
 IVCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
 }
Exemple #32
0
 internal ShaStream(Stream stream, CryptoStreamMode mode) : base(stream, mode)
 {
     sha       = SHA256.Create();
     shaStream = new CryptoStream(stream, sha, mode);
 }
Exemple #33
0
 static CryptoStream CreateCryptoStream(Stream stream, byte[] userID, string password, string pepper, CryptoStreamMode cryptoStreamMode)
 {
     if (stream == null)
         throw new ArgumentNullException ("stream");
     if (userID == null)
         throw new ArgumentNullException ("userID");
     if (password == null)
         throw new ArgumentNullException ("password");
     if (pepper == null)
         throw new ArgumentNullException ("pepper");
     var Rij = CreateRijndael (userID, password, pepper);
     ICryptoTransform RijTrans = Rij.CreateDecryptor ();
     CryptoStream cstream = new CryptoStream (stream, RijTrans, cryptoStreamMode);
     return cstream;
 }
Exemple #34
0
 protected override Stream CreateCryptoStream(Stream target, ICryptoTransform transform, CryptoStreamMode mode)
 {
     return(new CryptoStream(target, transform, mode));
 }
 public BaseStreamNonDisposingCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 { }
Exemple #36
0
 public NotClosingCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
 }
Exemple #37
0
 public CryptoStreamEx(Stream s, ICryptoTransform t, CryptoStreamMode m,
                       SymmetricAlgorithm a) : base(s, t, m)
 {
     m_t = t;
     m_a = a;
 }
Exemple #38
0
 protected abstract Stream CreateCryptoStream(Stream target, ICryptoTransform transform, CryptoStreamMode mode);
 public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode);
Exemple #40
0
 public HashStream(Stream stream, CryptoStreamMode mode, HashAlgorithmName hashAlgorithmName, HashAlgorithm hashCalculator = null)
     : base(stream, hashCalculator ?? (hashCalculator = HashAlgorithm.Create(hashAlgorithmName.Name)), mode)
 {
     HashAlgorithmName   = hashAlgorithmName;
     this.hashCalculator = hashCalculator;
 }
Exemple #41
0
 public CryptoStream(System.IO.Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
 {
     return(default(CryptoStream));
 }
Exemple #42
0
 // Constructors
 public CryptoStream(System.IO.Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
 {
 }
 public PwdTdsCryptoStream(System.IO.Stream Stream, ICryptoTransform Transform, CryptoStreamMode Mode)
     : base(Stream, Transform, Mode)
 {
     m_CryptoTransform = Transform;
     m_bDisposed       = false;
 }
        // Constructors

        public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
            : this(stream, transform, mode, false)
        {
        }
 public DisposingCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
     _stream = stream;
     _transform = transform;
 }
 public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
 {
   Contract.Requires(stream != null);
 }
        // can it be used by service worker?


        // the view-source is the shared key
        // the client creates a new key
        // to encrypted respond to


        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201411/20141108

        public __CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
        {
            // tested by ?


        }
Exemple #48
0
 /// <summary> Provides reading and writing to a stream of hexidecimal characters. </summary>
 public HexStream(Stream stream, CryptoStreamMode mode)
     : base(stream, new Transform(mode), mode) 
 { }
Exemple #49
0
 public AesCTRCryptoStream(Stream stream, AesCTRCryptoTransform transform, CryptoStreamMode streamMode) : this(stream, transform, streamMode, false)
 {
 }
Exemple #50
0
 public DerivedCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode) : base(stream, transform, mode)
 {
 }
 public CryptoStreamBase Create(System.IO.Stream stream, ICryptoTransform cryptoTransform, CryptoStreamMode cryptoStreamMode)
 {
     return new CryptoStreamWrapper(new CryptoStream(stream, cryptoTransform, cryptoStreamMode));
 }
Exemple #52
0
	internal ICryptoTransform GetCryptoTransform (CryptoStreamMode cryptoStreamMode) 
	{
		ICryptoTransform transform = null;
		MachineKeySection config = (MachineKeySection) WebConfigurationManager.GetSection (machineKeyConfigPath);
		byte [] vk = MachineKeySectionUtils.ValidationKeyBytes (config);

		switch (config.Validation) {
			case MachineKeyValidation.SHA1:
				transform = SHA1.Create ();
				break;

			case MachineKeyValidation.MD5:
				transform = MD5.Create ();
				break;

			case MachineKeyValidation.AES:
				InitializeEncryption ();
				if (cryptoStreamMode == CryptoStreamMode.Read){
					transform = Rijndael.Create().CreateDecryptor(vk, AES_IV);
				} else {
					transform = Rijndael.Create().CreateEncryptor(vk, AES_IV);
				}
				break;

			case MachineKeyValidation.TripleDES:
				InitializeEncryption ();
				if (cryptoStreamMode == CryptoStreamMode.Read){
					transform = TripleDES.Create().CreateDecryptor(vk, TripleDES_IV);
				} else {
					transform = TripleDES.Create().CreateEncryptor(vk, TripleDES_IV);
				}
				break;
		}

		return transform;
	}
 public NonClosingCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode, bool leaveOpen)
     : base(stream, transform, mode)
 {
     mLeaveOpen = leaveOpen;
 }
Exemple #54
0
 /// <summary>
 /// Creates new instance using 256 bit AES in CBC mode.
 /// </summary>
 /// <param name="stream">The stream on which to perform the cryptographic transformation.</param>
 /// <param name="password">Password used for key and IV derivation. UTF-8 encoding is assumed.</param>
 /// <param name="streamMode">The cryptographic transformation that is to be performed on the stream.</param>
 /// <exception cref="System.ArgumentNullException">Stream cannot be null. -or- Password cannot be null.</exception>
 /// <exception cref="System.ArgumentException">Stream mode must be either Read or Write. -or- Stream is not readable. -or- Stream is not writable.</exception>
 /// <exception cref="System.IO.InvalidDataException">Unexpected end of stream. -or- Salted stream expected.</exception>
 public OpenSslAesStream(Stream stream, String password, CryptoStreamMode streamMode)
     : this(stream, UTF8Encoding.UTF8.GetBytes(password), streamMode, 256, CipherMode.CBC)
 {
 }
Exemple #55
0
        // Constructors

        public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
            : this(stream, transform, mode, false)
        {
        }
Exemple #56
0
 IVCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
 }
Exemple #57
0
 public MinimalCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode) : base(stream, transform, mode) { }
Exemple #58
0
 public BaseStreamNonDisposingCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
 }
Exemple #59
0
 /// <summary> Provides a crypto-transform used to read/write to a stream of hexidecimal characters. </summary>
 public Transform(CryptoStreamMode mode) { _mode = mode; }
 public SilentCryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
     // stream is already implicitly validated non-null in the base constructor.
     this.underlyingStream = stream;
 }