本文整理汇总了C#中System.Security.SecureString.GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# SecureString.GetBuffer方法的具体用法?C# SecureString.GetBuffer怎么用?C# SecureString.GetBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.SecureString
的用法示例。
在下文中一共展示了SecureString.GetBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SecureStringToCoTaskMemAnsi
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;
}
示例2: SecureStringToCoTaskMemUnicode
public static IntPtr SecureStringToCoTaskMemUnicode (SecureString s)
{
if (s == null)
throw new ArgumentNullException ("s");
int len = s.Length;
IntPtr ctm = AllocCoTaskMem (len * 2 + 2);
byte [] buffer = null;
try {
buffer = s.GetBuffer ();
for (int i = 0; i < len; i++)
WriteInt16 (ctm, i * 2, (short) ((buffer [(i*2)] << 8) | (buffer [i*2+1])));
WriteInt16 (ctm, buffer.Length, 0);
} finally {
if (buffer != null)
for (int i = buffer.Length; i > 0; ){
i--;
buffer [i] = 0;
}
}
return ctm;
}
示例3: SecureStringToBSTR
public static IntPtr SecureStringToBSTR (SecureString s)
{
if (s == null)
throw new ArgumentNullException ("s");
int len = s.Length;
IntPtr ctm = AllocCoTaskMem ((len+1) * 2 + 4);
byte [] buffer = null;
WriteInt32 (ctm, 0, len*2);
try {
buffer = s.GetBuffer ();
for (int i = 0; i < len; i++)
WriteInt16 (ctm, 4 + (i * 2), (short) ((buffer [(i*2)] << 8) | (buffer [i*2+1])));
WriteInt16 (ctm, 4 + buffer.Length, 0);
} finally {
if (buffer != null)
for (int i = buffer.Length; i > 0; ){
i--;
buffer [i] = 0;
}
}
return (IntPtr) ((long)ctm + 4);
}