Exemplo n.º 1
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 public void Dispose()
 {
     lock (_methodLock)
     {
         if (_encryptedBuffer != null && !_encryptedBuffer.IsInvalid)
         {
             _encryptedBuffer.Dispose();
             _encryptedBuffer = null;
         }
     }
 }
Exemplo n.º 2
0
        [System.Security.SecurityCritical]  // auto-generated
        private void ProtectMemory(SafeBSTRHandle decryptedBuffer)
        {
            Debug.Assert(!decryptedBuffer.IsInvalid, "Invalid buffer!");

            if (_decryptedLength == 0)
            {
                return;
            }

            try
            {
                SafeBSTRHandle newEncryptedBuffer = null;
                if (Interop.Crypt32.CryptProtectData(decryptedBuffer, out newEncryptedBuffer))
                {
                    _encryptedBuffer.Dispose();
                    _encryptedBuffer = newEncryptedBuffer;
                }
                else
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }
            }
            finally
            {
                decryptedBuffer.ClearBuffer();
            }
        }
Exemplo n.º 3
0
        [System.Security.SecurityCritical]  // auto-generated
        private void EnsureCapacity(ref SafeBSTRHandle decryptedBuffer, int capacity)
        {
            if (capacity > MaxLength)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.ArgumentOutOfRange_Capacity);
            }

            if (capacity <= _decryptedLength)
            {
                return;
            }

            SafeBSTRHandle newBuffer = SafeBSTRHandle.Allocate(null, (uint)capacity);

            SafeBSTRHandle.Copy(decryptedBuffer, newBuffer, (uint)_decryptedLength * sizeof(char));
            decryptedBuffer.Dispose();
            decryptedBuffer = newBuffer;
        }
Exemplo n.º 4
0
        private void EnsureCapacity(int capacity)
        {
            if (capacity > MaxLength)
            {
                throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_Capacity);
            }

            Debug.Assert(_buffer != null);
            if (((uint)capacity * sizeof(char)) <= _buffer.ByteLength)
            {
                return;
            }

            SafeBSTRHandle oldBuffer = _buffer;
            SafeBSTRHandle newBuffer = SafeBSTRHandle.Allocate(GetAlignedSize((uint)capacity));

            SafeBSTRHandle.Copy(oldBuffer, newBuffer, (uint)_decryptedLength * sizeof(char));
            _buffer = newBuffer;
            oldBuffer.Dispose();
        }
Exemplo n.º 5
0
        [System.Security.SecurityCritical]  // auto-generated
        private void ProtectMemory(SafeBSTRHandle decryptedBuffer)
        {
            Debug.Assert(!decryptedBuffer.IsInvalid, "Invalid buffer!");

            if (_decryptedLength == 0)
            {
                return;
            }

            try
            {
                SafeBSTRHandle newEncryptedBuffer = null;
                if (Interop.Crypt32.CryptProtectData(decryptedBuffer, out newEncryptedBuffer))
                {
                    _encryptedBuffer.Dispose();
                    _encryptedBuffer = newEncryptedBuffer;
                }
                else
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }
            }
            finally
            {
                decryptedBuffer.ClearBuffer();
                decryptedBuffer.Dispose();
            }
        }
Exemplo n.º 6
0
        [System.Security.SecurityCritical]  // auto-generated
        private void EnsureCapacity(ref SafeBSTRHandle decryptedBuffer, int capacity)
        {
            if (capacity > MaxLength)
            {
                throw new ArgumentOutOfRangeException("capacity", SR.ArgumentOutOfRange_Capacity);
            }

            if (capacity <= _decryptedLength)
            {
                return;
            }

            SafeBSTRHandle newBuffer = SafeBSTRHandle.Allocate(null, (uint)capacity);
            SafeBSTRHandle.Copy(decryptedBuffer, newBuffer, (uint)_decryptedLength * sizeof(char));
            decryptedBuffer.Dispose();
            decryptedBuffer = newBuffer;
        }