System.Security.SecureString.GetBuffer C# (CSharp) Method

GetBuffer() private method

private GetBuffer ( ) : byte[]
return byte[]
		internal byte[] GetBuffer ()
		{
			byte[] secret = new byte[length << 1];
			try {
				Decrypt ();
				Buffer.BlockCopy (data, 0, secret, 0, secret.Length);
			}
			finally {
				Encrypt ();
			}
			// NOTE: CALLER IS RESPONSIBLE TO ZEROIZE THE DATA
			return secret;
		}
	}

Usage Example

Example #1
0
		public static IntPtr SecureStringToCoTaskMemAnsi (SecureString s)
		{
			if (s == null)
				throw new ArgumentNullException ("s");
			int len = s.Length;
			IntPtr ctm = AllocCoTaskMem (len + 1);
			byte [] copy = new byte [len+1];

			try {
				byte [] buffer = s.GetBuffer ();
				int i = 0, j = 0;
				for (; i < len; i++, j += 2){
					copy [i] = buffer [j+1];
					buffer [j] = 0;
					buffer [j+1] = 0;
				}
				copy [i] = 0;
				copy_to_unmanaged (copy, 0, ctm, len+1);
			} finally {
				// Ensure that we clear the buffer.
				for (int i = len; i > 0; ){
					i--;
					copy [i] = 0;
				}
			}
			return ctm;
		}
All Usage Examples Of System.Security.SecureString::GetBuffer