本文整理汇总了VB.NET中System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocAnsi方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Marshal.SecureStringToGlobalAllocAnsi方法的具体用法?VB.NET Marshal.SecureStringToGlobalAllocAnsi怎么用?VB.NET Marshal.SecureStringToGlobalAllocAnsi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.Marshal
的用法示例。
在下文中一共展示了Marshal.SecureStringToGlobalAllocAnsi方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Runtime.InteropServices
Imports System.Security
Module Example
Sub Main()
Dim unmanagedRef As IntPtr
' Ask the user for a password.
Console.Write("Please enter your password: ")
Dim passWord As SecureString = GetPassword()
Console.WriteLine("Copying and decrypting the string to unmanaged memory...")
' Copy the Secure string to unmanaged memory (and decrypt it).
unmanagedRef = Marshal.SecureStringToGlobalAllocAnsi(passWord)
passWord.Dispose()
If unmanagedRef <> IntPtr.Zero Then
Console.WriteLine("Zeroing out unmanaged memory...")
Marshal.ZeroFreeGlobalAllocAnsi(unmanagedRef)
End If
Console.WriteLine("Done.")
End Sub
Function GetPassword() As SecureString
Dim password As New SecureString()
' get the first character of the password
Dim nextKey As ConsoleKeyInfo = Console.ReadKey(True)
While nextKey.Key <> ConsoleKey.Enter
If nextKey.Key = ConsoleKey.BackSpace Then
If password.Length > 0 Then
password.RemoveAt(password.Length - 1)
' Erase the last * as well.
Console.Write(nextKey.KeyChar)
Console.Write(" ")
Console.Write(nextKey.KeyChar)
End If
Else
password.AppendChar(nextKey.KeyChar)
Console.Write("*")
End If
nextKey = Console.ReadKey(True)
End While
Console.WriteLine()
' lock the password down
password.MakeReadOnly()
Return password
End Function
End Module
开发者ID:VB.NET开发者,项目名称:System.Runtime.InteropServices,代码行数:54,代码来源:Marshal.SecureStringToGlobalAllocAnsi
输出:
Please enter your password: ******** Copying and decrypting the string to unmanaged memory... Zeroing out unmanaged memory... Done.