using System; using System.Runtime.ConstrainedExecution; namespace System.Security { /// Represents text that should be kept confidential. The text is encrypted for privacy when being used, and deleted from computer memory when no longer needed. This class cannot be inherited. // Token: 0x020005C9 RID: 1481 [MonoTODO("work in progress - encryption is missing")] public sealed class SecureString : CriticalFinalizerObject, IDisposable { /// Initializes a new instance of the class. /// An error occurred while encrypting or decrypting the value of this instance. /// This operation is not supported on this platform. // Token: 0x060035FF RID: 13823 RVA: 0x000B8868 File Offset: 0x000B6A68 public SecureString() { this.Alloc(8, false); } /// Initializes a new instance of the class from a subarray of objects. /// A pointer to an array of objects. /// The number of elements of to include in the new instance. /// /// is null. /// /// is less than zero or greater than 65536. /// An error occurred while encrypting or decrypting the value of this secure string. /// This operation is not supported on this platform. // Token: 0x06003600 RID: 13824 RVA: 0x000B8878 File Offset: 0x000B6A78 [CLSCompliant(false)] public unsafe SecureString(char* value, int length) { if (value == null) { throw new ArgumentNullException("value"); } if (length < 0 || length > 65536) { throw new ArgumentOutOfRangeException("length", "< 0 || > 65536"); } this.length = length; this.Alloc(length, false); int num = 0; for (int i = 0; i < length; i++) { char c = *(value++); this.data[num++] = (byte)(c >> 8); this.data[num++] = (byte)c; } this.Encrypt(); } /// Gets the number of characters in the current secure string. /// The number of objects in this secure string. /// This secure string has already been disposed. // Token: 0x17000A8F RID: 2703 // (get) Token: 0x06003602 RID: 13826 RVA: 0x000B8914 File Offset: 0x000B6B14 public int Length { get { if (this.disposed) { throw new ObjectDisposedException("SecureString"); } return this.length; } } /// Appends a character to the end of the current secure string. /// A character to append to this secure string. /// This secure string has already been disposed. /// This secure string is read-only. /// Performing this operation would make the length of this secure string greater than 65536 characters. /// An error occurred while encrypting or decrypting the value of this secure string. // Token: 0x06003603 RID: 13827 RVA: 0x000B8934 File Offset: 0x000B6B34 public void AppendChar(char c) { if (this.disposed) { throw new ObjectDisposedException("SecureString"); } if (this.read_only) { throw new InvalidOperationException(Locale.GetText("SecureString is read-only.")); } if (this.length == 65536) { throw new ArgumentOutOfRangeException("length", "> 65536"); } try { this.Decrypt(); int num = this.length * 2; this.Alloc(++this.length, true); this.data[num++] = (byte)(c >> 8); this.data[num++] = (byte)c; } finally { this.Encrypt(); } } /// Deletes the value of the current secure string. /// This secure string has already been disposed. /// This secure string is read-only. // Token: 0x06003604 RID: 13828 RVA: 0x000B8A00 File Offset: 0x000B6C00 public void Clear() { if (this.disposed) { throw new ObjectDisposedException("SecureString"); } if (this.read_only) { throw new InvalidOperationException(Locale.GetText("SecureString is read-only.")); } Array.Clear(this.data, 0, this.data.Length); this.length = 0; } /// Creates a copy of the current secure string. /// A duplicate of this secure string. /// This secure string has already been disposed. /// An error occurred while encrypting or decrypting the value of this secure string. // Token: 0x06003605 RID: 13829 RVA: 0x000B8A5C File Offset: 0x000B6C5C public SecureString Copy() { return new SecureString { data = (byte[])this.data.Clone(), length = this.length }; } /// Releases all resources used by the current object. // Token: 0x06003606 RID: 13830 RVA: 0x000B8A94 File Offset: 0x000B6C94 public void Dispose() { this.disposed = true; if (this.data != null) { Array.Clear(this.data, 0, this.data.Length); this.data = null; } this.length = 0; } /// Inserts a character in this secure string at the specified index position. /// The index position where parameter is inserted. /// The character to insert. /// This secure string has already been disposed. /// This secure string is read-only. /// /// is less than zero, or greater than the length of this secure string.-or-Performing this operation would make the length of this secure string greater than 65536 characters. /// An error occurred while encrypting or decrypting the value of this secure string. // Token: 0x06003607 RID: 13831 RVA: 0x000B8AD8 File Offset: 0x000B6CD8 public void InsertAt(int index, char c) { if (this.disposed) { throw new ObjectDisposedException("SecureString"); } if (this.read_only) { throw new InvalidOperationException(Locale.GetText("SecureString is read-only.")); } if (index < 0 || index > this.length) { throw new ArgumentOutOfRangeException("index", "< 0 || > length"); } if (this.length >= 65536) { string text = Locale.GetText("Maximum string size is '{0}'.", new object[] { 65536 }); throw new ArgumentOutOfRangeException("index", text); } try { this.Decrypt(); this.Alloc(++this.length, true); int num = index * 2; Buffer.BlockCopy(this.data, num, this.data, num + 2, this.data.Length - num - 2); this.data[num++] = (byte)(c >> 8); this.data[num] = (byte)c; } finally { this.Encrypt(); } } /// Indicates whether this secure string is marked read-only. /// true if this secure string is marked read-only; otherwise, false. /// This secure string has already been disposed. // Token: 0x06003608 RID: 13832 RVA: 0x000B8BF8 File Offset: 0x000B6DF8 public bool IsReadOnly() { if (this.disposed) { throw new ObjectDisposedException("SecureString"); } return this.read_only; } /// Makes the text value of this secure string read-only. /// This secure string has already been disposed. // Token: 0x06003609 RID: 13833 RVA: 0x000B8C18 File Offset: 0x000B6E18 public void MakeReadOnly() { this.read_only = true; } /// Removes the character at the specified index position from this secure string. /// The index position of a character in this secure string. /// This secure string has already been disposed. /// This secure string is read-only. /// /// is less than zero, or greater than or equal to the length of this secure string. /// An error occurred while encrypting or decrypting the value of this secure string. // Token: 0x0600360A RID: 13834 RVA: 0x000B8C24 File Offset: 0x000B6E24 public void RemoveAt(int index) { if (this.disposed) { throw new ObjectDisposedException("SecureString"); } if (this.read_only) { throw new InvalidOperationException(Locale.GetText("SecureString is read-only.")); } if (index < 0 || index >= this.length) { throw new ArgumentOutOfRangeException("index", "< 0 || > length"); } try { this.Decrypt(); Buffer.BlockCopy(this.data, index + 1, this.data, index, this.data.Length - index - 1); this.Alloc(--this.length, true); } finally { this.Encrypt(); } } /// Replaces the existing character at the specified index position with another character. /// The index position of an existing character in this secure string /// A character that replaces the existing character. /// This secure string has already been disposed. /// This secure string is read-only. /// /// is less than zero, or greater than or equal to the length of this secure string. /// An error occurred while encrypting or decrypting the value of this secure string. // Token: 0x0600360B RID: 13835 RVA: 0x000B8CEC File Offset: 0x000B6EEC public void SetAt(int index, char c) { if (this.disposed) { throw new ObjectDisposedException("SecureString"); } if (this.read_only) { throw new InvalidOperationException(Locale.GetText("SecureString is read-only.")); } if (index < 0 || index >= this.length) { throw new ArgumentOutOfRangeException("index", "< 0 || > length"); } try { this.Decrypt(); int num = index * 2; this.data[num++] = (byte)(c >> 8); this.data[num] = (byte)c; } finally { this.Encrypt(); } } // Token: 0x0600360C RID: 13836 RVA: 0x000B8D9C File Offset: 0x000B6F9C private void Encrypt() { if (this.data == null || this.data.Length > 0) { } } // Token: 0x0600360D RID: 13837 RVA: 0x000B8DB8 File Offset: 0x000B6FB8 private void Decrypt() { if (this.data == null || this.data.Length > 0) { } } // Token: 0x0600360E RID: 13838 RVA: 0x000B8DD4 File Offset: 0x000B6FD4 private void Alloc(int length, bool realloc) { if (length < 0 || length > 65536) { throw new ArgumentOutOfRangeException("length", "< 0 || > 65536"); } int num = (length >> 3) + (((length & 7) != 0) ? 1 : 0) << 4; if (realloc && this.data != null && num == this.data.Length) { return; } if (realloc) { byte[] array = new byte[num]; Array.Copy(this.data, 0, array, 0, Math.Min(this.data.Length, array.Length)); Array.Clear(this.data, 0, this.data.Length); this.data = array; } else { this.data = new byte[num]; } } // Token: 0x0600360F RID: 13839 RVA: 0x000B8E90 File Offset: 0x000B7090 internal byte[] GetBuffer() { byte[] array = new byte[this.length << 1]; try { this.Decrypt(); Buffer.BlockCopy(this.data, 0, array, 0, array.Length); } finally { this.Encrypt(); } return array; } // Token: 0x0400161D RID: 5661 private const int BlockSize = 16; // Token: 0x0400161E RID: 5662 private const int MaxSize = 65536; // Token: 0x0400161F RID: 5663 private int length; // Token: 0x04001620 RID: 5664 private bool disposed; // Token: 0x04001621 RID: 5665 private bool read_only; // Token: 0x04001622 RID: 5666 private byte[] data; } }