<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How rdp passwords are encrypted 2</title>
	<atom:link href="http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-rdp-passwords-are-encrypted-2</link>
	<description>About Terminal Server, Citrix, Delphi and other stuff</description>
	<lastBuildDate>Tue, 31 Aug 2010 10:13:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Decrypt Remote Desktop Mobile password &#124; Windows CE Programming</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-1393</link>
		<dc:creator>Decrypt Remote Desktop Mobile password &#124; Windows CE Programming</dc:creator>
		<pubDate>Fri, 19 Feb 2010 05:25:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-1393</guid>
		<description>[...] I found the article about decrypting saved RDP passwords at http://www.jaysonragasa.net/post/EncryptDecrypt-RDP-Password.aspx and http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/. [...]</description>
		<content:encoded><![CDATA[<p>[...] I found the article about decrypting saved RDP passwords at <a href="http://www.jaysonragasa.net/post/EncryptDecrypt-RDP-Password.aspx" rel="nofollow">http://www.jaysonragasa.net/post/EncryptDecrypt-RDP-Password.aspx</a> and <a href="http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/" rel="nofollow">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/</a>. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: maurizio</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-1269</link>
		<dc:creator>maurizio</dc:creator>
		<pubDate>Mon, 09 Nov 2009 20:03:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-1269</guid>
		<description>I want automated the file creation  with .rdp extension for remote desktop and your program is very good but in my vb6 program the call at your program is not the good way. 

is not possible for you create an rdp.dll with the encrypt function only ????

Best regards</description>
		<content:encoded><![CDATA[<p>I want automated the file creation  with .rdp extension for remote desktop and your program is very good but in my vb6 program the call at your program is not the good way. </p>
<p>is not possible for you create an rdp.dll with the encrypt function only ????</p>
<p>Best regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim McGrath</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-1213</link>
		<dc:creator>Tim McGrath</dc:creator>
		<pubDate>Wed, 09 Sep 2009 19:19:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-1213</guid>
		<description>I used this tool to encrypt my password and put it in an RDP file.

It seems that Windows (XP Pro SP3) ignores the username and password entries that I put in the RDP file and will only use the credentials stored in the registry.  It doesn&#039;t matter whether I launch the RDP by double-clicking it or launching it using mstsc from a command prompt.

Does anyone know how to get Windows use the credentials I have stored in the RDP file?  Is it because of the version of mstsc (and supporting files) that I am using?  A policy?  Thanks a lot</description>
		<content:encoded><![CDATA[<p>I used this tool to encrypt my password and put it in an RDP file.</p>
<p>It seems that Windows (XP Pro SP3) ignores the username and password entries that I put in the RDP file and will only use the credentials stored in the registry.  It doesn&#8217;t matter whether I launch the RDP by double-clicking it or launching it using mstsc from a command prompt.</p>
<p>Does anyone know how to get Windows use the credentials I have stored in the RDP file?  Is it because of the version of mstsc (and supporting files) that I am using?  A policy?  Thanks a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nullstring</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-946</link>
		<dc:creator>Nullstring</dc:creator>
		<pubDate>Sun, 05 Apr 2009 02:42:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-946</guid>
		<description>Hey thanks for this info. Learned a lot from you.

I have done the same thing in C# but using DataProtection found in http://msdn.microsoft.com/en-us/library/aa302402.aspx#secnetht07_topic4

You can download the Encrypt/Decrypt sample here.
http://multirdpc.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25591#ReleaseFiles</description>
		<content:encoded><![CDATA[<p>Hey thanks for this info. Learned a lot from you.</p>
<p>I have done the same thing in C# but using DataProtection found in <a href="http://msdn.microsoft.com/en-us/library/aa302402.aspx#secnetht07_topic4" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa302402.aspx#secnetht07_topic4</a></p>
<p>You can download the Encrypt/Decrypt sample here.<br />
<a href="http://multirdpc.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25591#ReleaseFiles" rel="nofollow">http://multirdpc.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25591#ReleaseFiles</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Angeliccare</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-689</link>
		<dc:creator>Angeliccare</dc:creator>
		<pubDate>Tue, 02 Dec 2008 16:23:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-689</guid>
		<description>Dominique Descat, if you will not be against, I would use your code for one of sourceforge projects: RDPman and it&#039;s derivate?

Thanks.

(In e-mail it&#039;s not .ur - shold be .ru, thanks for understanding)</description>
		<content:encoded><![CDATA[<p>Dominique Descat, if you will not be against, I would use your code for one of sourceforge projects: RDPman and it&#8217;s derivate?</p>
<p>Thanks.</p>
<p>(In e-mail it&#8217;s not .ur &#8211; shold be .ru, thanks for understanding)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fedro ponce de leon</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-601</link>
		<dc:creator>Fedro ponce de leon</dc:creator>
		<pubDate>Sat, 01 Nov 2008 15:40:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-601</guid>
		<description>Is there any VC++ code available?</description>
		<content:encoded><![CDATA[<p>Is there any VC++ code available?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lokesh</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-578</link>
		<dc:creator>Lokesh</dc:creator>
		<pubDate>Mon, 13 Oct 2008 07:04:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-578</guid>
		<description>Hi Remko !!
Can you please provide the source code in VC++ 6.0/mfc for the encryption/decryption tool that you have used in your &#039;Remote Desktop Password Encryption &amp; Decryption Tool (395)&#039;.

Thanks in advance :)</description>
		<content:encoded><![CDATA[<p>Hi Remko !!<br />
Can you please provide the source code in VC++ 6.0/mfc for the encryption/decryption tool that you have used in your &#8216;Remote Desktop Password Encryption &amp; Decryption Tool (395)&#8217;.</p>
<p>Thanks in advance <img src='http://www.remkoweijnen.nl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jignesh</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-234</link>
		<dc:creator>Jignesh</dc:creator>
		<pubDate>Sat, 05 Jul 2008 14:38:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-234</guid>
		<description>Hello Remko,

Can you please give me code in C++ which does password encryption same as RDP does?

I am working on very urgent requirement.

It will be greate if you help me.

Thanks

Jignesh</description>
		<content:encoded><![CDATA[<p>Hello Remko,</p>
<p>Can you please give me code in C++ which does password encryption same as RDP does?</p>
<p>I am working on very urgent requirement.</p>
<p>It will be greate if you help me.</p>
<p>Thanks</p>
<p>Jignesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-210</link>
		<dc:creator>Gareth</dc:creator>
		<pubDate>Wed, 11 Jun 2008 15:06:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-210</guid>
		<description>Hi Remko,

In your original post in the comments you wrote:
&quot;I will write a new demo app to accompany the article that encrypts the full length password and can encrypt password that are valid for machine instead of user.
This makes it possible (eg) to publish an rdp connection.&quot;

I&#039;m just wondering if this is the app you were talking about. I tried to encrypt a password using the tool but didn&#039;t see any option for machine vs. user; I tried it anyway but it doesn&#039;t seem to work for any other user that signs on to the machine besides the one the password was encrypted under.

Any tips? Basically what I&#039;m trying to do is make an RDP file that I can save under All Users\Desktop and any user who signs in can use it to connect to another machine using a single username/password. I tried your LaunchRDP utility however the missing &#039;toolbar&#039; is an issue for me (users need to be able to minimize the remote desktop window)

Thanks!</description>
		<content:encoded><![CDATA[<p>Hi Remko,</p>
<p>In your original post in the comments you wrote:<br />
&#8220;I will write a new demo app to accompany the article that encrypts the full length password and can encrypt password that are valid for machine instead of user.<br />
This makes it possible (eg) to publish an rdp connection.&#8221;</p>
<p>I&#8217;m just wondering if this is the app you were talking about. I tried to encrypt a password using the tool but didn&#8217;t see any option for machine vs. user; I tried it anyway but it doesn&#8217;t seem to work for any other user that signs on to the machine besides the one the password was encrypted under.</p>
<p>Any tips? Basically what I&#8217;m trying to do is make an RDP file that I can save under All Users\Desktop and any user who signs in can use it to connect to another machine using a single username/password. I tried your LaunchRDP utility however the missing &#8216;toolbar&#8217; is an issue for me (users need to be able to minimize the remote desktop window)</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dominique Descat</title>
		<link>http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/comment-page-1/#comment-195</link>
		<dc:creator>Dominique Descat</dc:creator>
		<pubDate>Mon, 19 May 2008 12:56:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2008/03/02/how-rdp-passwords-are-encrypted-2/#comment-195</guid>
		<description>Remko, thanks for your Web site, thanks also to Justin Shepard for the translation into VB.
I have change something’s within his code and adapted the sub main to create an executable object with VB express 2005 (please transfer this news to Jeremy...)
Concerning my main code, I use 2 parameters (arguments): input file name &amp; output file name. At the end of the encryption, the 1329 bytes are completed with the end of the encryption of 256 spaces.
####################################
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports Microsoft.VisualBasic

Public Module RdpEncrypt

    Public Class DPAPI
         _
        Private Shared Function CryptProtectData( _
                    ByRef pPlainText As DATA_BLOB, _
                    ByVal szDescription As String, _
                    ByRef pEntropy As DATA_BLOB, _
                    ByVal pReserved As IntPtr, _
                    ByRef pPrompt As CRYPTPROTECT_PROMPTSTRUCT, _
                    ByVal dwFlags As Integer, _
                    ByRef pCipherText As DATA_BLOB _
                ) As Boolean
        End Function

         _
        Private Shared Function CryptUnprotectData( _
                    ByRef pCipherText As DATA_BLOB, _
                    ByRef pszDescription As String, _
                    ByRef pEntropy As DATA_BLOB, _
                    ByVal pReserved As IntPtr, _
                    ByRef pPrompt As CRYPTPROTECT_PROMPTSTRUCT, _
                    ByVal dwFlags As Integer, _
                    ByRef pPlainText As DATA_BLOB _
                ) As Boolean
        End Function

         _
        Friend Structure DATA_BLOB
            Public cbData As Integer
            Public pbData As IntPtr
        End Structure

         _
        Friend Structure CRYPTPROTECT_PROMPTSTRUCT
            Public cbSize As Integer
            Public dwPromptFlags As Integer
            Public hwndApp As IntPtr
            Public szPrompt As String
        End Structure

        Private Const CRYPTPROTECT_UI_FORBIDDEN As Integer = 1
        Private Const CRYPTPROTECT_LOCAL_MACHINE As Integer = 4

        Private Shared Sub InitPrompt _
        ( _
            ByRef ps As CRYPTPROTECT_PROMPTSTRUCT _
        )
            ps.cbSize = Marshal.SizeOf(GetType(CRYPTPROTECT_PROMPTSTRUCT))
            ps.dwPromptFlags = 0
            ps.hwndApp = IntPtr.Zero
            ps.szPrompt = Nothing
        End Sub

        Private Shared Sub InitBLOB _
        ( _
            ByVal data As Byte(), _
            ByRef blob As DATA_BLOB _
        )
            &#039; Use empty array for null parameter.
            If data Is Nothing Then
                data = New Byte(0) {}
            End If

            &#039; Allocate memory for the BLOB data.
            blob.pbData = Marshal.AllocHGlobal(data.Length)

            &#039; Make sure that memory allocation was successful.
            If blob.pbData.Equals(IntPtr.Zero) Then
                Throw New Exception( _
                        &quot;Unable to allocate data buffer for BLOB structure.&quot;)
            End If

            &#039; Specify number of bytes in the BLOB.
            blob.cbData = data.Length
            Marshal.Copy(data, 0, blob.pbData, data.Length)
        End Sub

        Public Enum KeyType
            UserKey = 1
            MachineKey
        End Enum

        Private Shared defaultKeyType As KeyType = KeyType.UserKey

        Public Shared Function Encrypt _
        ( _
            ByVal keyType As KeyType, _
            ByVal plainText As String, _
            ByVal entropy As String, _
            ByVal description As String _
        ) As String
            If plainText Is Nothing Then
                plainText = String.Empty
            End If
            If entropy Is Nothing Then
                entropy = String.Empty
            End If

            Dim result As Byte()
            Dim encrypted As String = &quot;&quot;
            Dim i As Integer
            result = Encrypt(keyType, _
                             Encoding.Unicode.GetBytes(plainText), _
                             Encoding.Unicode.GetBytes(entropy), _
                             description)
            For i = 0 To result.Length - 1
                encrypted = encrypted &amp; Convert.ToString(result(i), 16).PadLeft(2, &quot;0&quot;).ToUpper()
            Next
            Return encrypted.ToString()
        End Function

        Public Shared Function Encrypt _
        ( _
            ByVal keyType As KeyType, _
            ByVal plainTextBytes As Byte(), _
            ByVal entropyBytes As Byte(), _
            ByVal description As String _
        ) As Byte()
            If plainTextBytes Is Nothing Then
                plainTextBytes = New Byte(0) {}
            End If

            If entropyBytes Is Nothing Then
                entropyBytes = New Byte(0) {}
            End If

            If description Is Nothing Then
                description = String.Empty
            End If

            Dim plainTextBlob As DATA_BLOB = New DATA_BLOB
            Dim cipherTextBlob As DATA_BLOB = New DATA_BLOB
            Dim entropyBlob As DATA_BLOB = New DATA_BLOB

            Dim prompt As _
                    CRYPTPROTECT_PROMPTSTRUCT = New CRYPTPROTECT_PROMPTSTRUCT
            InitPrompt(prompt)

            Try
                Try
                    InitBLOB(plainTextBytes, plainTextBlob)
                Catch ex As Exception
                    Throw New Exception(&quot;Cannot initialize plaintext BLOB.&quot;, ex)
                End Try

                Try
                    InitBLOB(entropyBytes, entropyBlob)
                Catch ex As Exception
                    Throw New Exception(&quot;Cannot initialize entropy BLOB.&quot;, ex)
                End Try

                Dim flags As Integer = CRYPTPROTECT_UI_FORBIDDEN

                If keyType = keyType.MachineKey Then
                    flags = flags Or (CRYPTPROTECT_LOCAL_MACHINE)
                End If

                Dim success As Boolean = CryptProtectData( _
                                                plainTextBlob, _
                                                description, _
                                                entropyBlob, _
                                                IntPtr.Zero, _
                                                prompt, _
                                                flags, _
                                                cipherTextBlob)

                If Not success Then
                    Dim errCode As Integer = Marshal.GetLastWin32Error()

                    Throw New Exception(&quot;CryptProtectData failed.&quot;, _
                                    New Win32Exception(errCode))
                End If

                Dim cipherTextBytes(cipherTextBlob.cbData) As Byte

                Marshal.Copy(cipherTextBlob.pbData, cipherTextBytes, 0, _
                                cipherTextBlob.cbData)

                Return cipherTextBytes
            Catch ex As Exception
                Throw New Exception(&quot;DPAPI was unable to encrypt data.&quot;, ex)
            Finally
                If Not (plainTextBlob.pbData.Equals(IntPtr.Zero)) Then
                    Marshal.FreeHGlobal(plainTextBlob.pbData)
                End If

                If Not (cipherTextBlob.pbData.Equals(IntPtr.Zero)) Then
                    Marshal.FreeHGlobal(cipherTextBlob.pbData)
                End If

                If Not (entropyBlob.pbData.Equals(IntPtr.Zero)) Then
                    Marshal.FreeHGlobal(entropyBlob.pbData)
                End If
            End Try
        End Function

    End Class

    Sub Main(ByVal args() As String)
        Try
            Dim INfilename As String = args(0) &#039;Input file with string without CrLf
            Dim OUTfilename As String = args(1) &#039;Output file
            Dim EncryptedText As String
            Dim TextToEncrypt As String
            Dim EncryptedBlank As String
            Dim BlankToEncrypt As String = Space(256)

            TextToEncrypt = File.ReadAllText(INfilename)

            EncryptedText = DPAPI.Encrypt(DPAPI.KeyType.MachineKey, TextToEncrypt, Nothing, &quot;psw&quot;)
            EncryptedBlank = DPAPI.Encrypt(DPAPI.KeyType.MachineKey, BlankToEncrypt, Nothing, &quot;psw&quot;)

            File.WriteAllText(OUTfilename, EncryptedText &amp; _
                Right(EncryptedBlank, 1329 - Len(EncryptedText))) &#039;Encrypted blank to complete to 1329

        Catch ex As Exception
            While Not (ex Is Nothing)
                Console.WriteLine(ex.Message)
                ex = ex.InnerException
            End While
        End Try
    End Sub

End Module
####################################
Regards.
Dominik</description>
		<content:encoded><![CDATA[<p>Remko, thanks for your Web site, thanks also to Justin Shepard for the translation into VB.<br />
I have change something’s within his code and adapted the sub main to create an executable object with VB express 2005 (please transfer this news to Jeremy&#8230;)<br />
Concerning my main code, I use 2 parameters (arguments): input file name &amp; output file name. At the end of the encryption, the 1329 bytes are completed with the end of the encryption of 256 spaces.<br />
####################################<br />
Imports System<br />
Imports System.IO<br />
Imports System.Text<br />
Imports System.Runtime.InteropServices<br />
Imports System.ComponentModel<br />
Imports Microsoft.VisualBasic</p>
<p>Public Module RdpEncrypt</p>
<p>    Public Class DPAPI<br />
         _<br />
        Private Shared Function CryptProtectData( _<br />
                    ByRef pPlainText As DATA_BLOB, _<br />
                    ByVal szDescription As String, _<br />
                    ByRef pEntropy As DATA_BLOB, _<br />
                    ByVal pReserved As IntPtr, _<br />
                    ByRef pPrompt As CRYPTPROTECT_PROMPTSTRUCT, _<br />
                    ByVal dwFlags As Integer, _<br />
                    ByRef pCipherText As DATA_BLOB _<br />
                ) As Boolean<br />
        End Function</p>
<p>         _<br />
        Private Shared Function CryptUnprotectData( _<br />
                    ByRef pCipherText As DATA_BLOB, _<br />
                    ByRef pszDescription As String, _<br />
                    ByRef pEntropy As DATA_BLOB, _<br />
                    ByVal pReserved As IntPtr, _<br />
                    ByRef pPrompt As CRYPTPROTECT_PROMPTSTRUCT, _<br />
                    ByVal dwFlags As Integer, _<br />
                    ByRef pPlainText As DATA_BLOB _<br />
                ) As Boolean<br />
        End Function</p>
<p>         _<br />
        Friend Structure DATA_BLOB<br />
            Public cbData As Integer<br />
            Public pbData As IntPtr<br />
        End Structure</p>
<p>         _<br />
        Friend Structure CRYPTPROTECT_PROMPTSTRUCT<br />
            Public cbSize As Integer<br />
            Public dwPromptFlags As Integer<br />
            Public hwndApp As IntPtr<br />
            Public szPrompt As String<br />
        End Structure</p>
<p>        Private Const CRYPTPROTECT_UI_FORBIDDEN As Integer = 1<br />
        Private Const CRYPTPROTECT_LOCAL_MACHINE As Integer = 4</p>
<p>        Private Shared Sub InitPrompt _<br />
        ( _<br />
            ByRef ps As CRYPTPROTECT_PROMPTSTRUCT _<br />
        )<br />
            ps.cbSize = Marshal.SizeOf(GetType(CRYPTPROTECT_PROMPTSTRUCT))<br />
            ps.dwPromptFlags = 0<br />
            ps.hwndApp = IntPtr.Zero<br />
            ps.szPrompt = Nothing<br />
        End Sub</p>
<p>        Private Shared Sub InitBLOB _<br />
        ( _<br />
            ByVal data As Byte(), _<br />
            ByRef blob As DATA_BLOB _<br />
        )<br />
            &#8216; Use empty array for null parameter.<br />
            If data Is Nothing Then<br />
                data = New Byte(0) {}<br />
            End If</p>
<p>            &#8216; Allocate memory for the BLOB data.<br />
            blob.pbData = Marshal.AllocHGlobal(data.Length)</p>
<p>            &#8216; Make sure that memory allocation was successful.<br />
            If blob.pbData.Equals(IntPtr.Zero) Then<br />
                Throw New Exception( _<br />
                        &#8220;Unable to allocate data buffer for BLOB structure.&#8221;)<br />
            End If</p>
<p>            &#8216; Specify number of bytes in the BLOB.<br />
            blob.cbData = data.Length<br />
            Marshal.Copy(data, 0, blob.pbData, data.Length)<br />
        End Sub</p>
<p>        Public Enum KeyType<br />
            UserKey = 1<br />
            MachineKey<br />
        End Enum</p>
<p>        Private Shared defaultKeyType As KeyType = KeyType.UserKey</p>
<p>        Public Shared Function Encrypt _<br />
        ( _<br />
            ByVal keyType As KeyType, _<br />
            ByVal plainText As String, _<br />
            ByVal entropy As String, _<br />
            ByVal description As String _<br />
        ) As String<br />
            If plainText Is Nothing Then<br />
                plainText = String.Empty<br />
            End If<br />
            If entropy Is Nothing Then<br />
                entropy = String.Empty<br />
            End If</p>
<p>            Dim result As Byte()<br />
            Dim encrypted As String = &#8220;&#8221;<br />
            Dim i As Integer<br />
            result = Encrypt(keyType, _<br />
                             Encoding.Unicode.GetBytes(plainText), _<br />
                             Encoding.Unicode.GetBytes(entropy), _<br />
                             description)<br />
            For i = 0 To result.Length &#8211; 1<br />
                encrypted = encrypted &amp; Convert.ToString(result(i), 16).PadLeft(2, &#8220;0&#8243;).ToUpper()<br />
            Next<br />
            Return encrypted.ToString()<br />
        End Function</p>
<p>        Public Shared Function Encrypt _<br />
        ( _<br />
            ByVal keyType As KeyType, _<br />
            ByVal plainTextBytes As Byte(), _<br />
            ByVal entropyBytes As Byte(), _<br />
            ByVal description As String _<br />
        ) As Byte()<br />
            If plainTextBytes Is Nothing Then<br />
                plainTextBytes = New Byte(0) {}<br />
            End If</p>
<p>            If entropyBytes Is Nothing Then<br />
                entropyBytes = New Byte(0) {}<br />
            End If</p>
<p>            If description Is Nothing Then<br />
                description = String.Empty<br />
            End If</p>
<p>            Dim plainTextBlob As DATA_BLOB = New DATA_BLOB<br />
            Dim cipherTextBlob As DATA_BLOB = New DATA_BLOB<br />
            Dim entropyBlob As DATA_BLOB = New DATA_BLOB</p>
<p>            Dim prompt As _<br />
                    CRYPTPROTECT_PROMPTSTRUCT = New CRYPTPROTECT_PROMPTSTRUCT<br />
            InitPrompt(prompt)</p>
<p>            Try<br />
                Try<br />
                    InitBLOB(plainTextBytes, plainTextBlob)<br />
                Catch ex As Exception<br />
                    Throw New Exception(&#8220;Cannot initialize plaintext BLOB.&#8221;, ex)<br />
                End Try</p>
<p>                Try<br />
                    InitBLOB(entropyBytes, entropyBlob)<br />
                Catch ex As Exception<br />
                    Throw New Exception(&#8220;Cannot initialize entropy BLOB.&#8221;, ex)<br />
                End Try</p>
<p>                Dim flags As Integer = CRYPTPROTECT_UI_FORBIDDEN</p>
<p>                If keyType = keyType.MachineKey Then<br />
                    flags = flags Or (CRYPTPROTECT_LOCAL_MACHINE)<br />
                End If</p>
<p>                Dim success As Boolean = CryptProtectData( _<br />
                                                plainTextBlob, _<br />
                                                description, _<br />
                                                entropyBlob, _<br />
                                                IntPtr.Zero, _<br />
                                                prompt, _<br />
                                                flags, _<br />
                                                cipherTextBlob)</p>
<p>                If Not success Then<br />
                    Dim errCode As Integer = Marshal.GetLastWin32Error()</p>
<p>                    Throw New Exception(&#8220;CryptProtectData failed.&#8221;, _<br />
                                    New Win32Exception(errCode))<br />
                End If</p>
<p>                Dim cipherTextBytes(cipherTextBlob.cbData) As Byte</p>
<p>                Marshal.Copy(cipherTextBlob.pbData, cipherTextBytes, 0, _<br />
                                cipherTextBlob.cbData)</p>
<p>                Return cipherTextBytes<br />
            Catch ex As Exception<br />
                Throw New Exception(&#8220;DPAPI was unable to encrypt data.&#8221;, ex)<br />
            Finally<br />
                If Not (plainTextBlob.pbData.Equals(IntPtr.Zero)) Then<br />
                    Marshal.FreeHGlobal(plainTextBlob.pbData)<br />
                End If</p>
<p>                If Not (cipherTextBlob.pbData.Equals(IntPtr.Zero)) Then<br />
                    Marshal.FreeHGlobal(cipherTextBlob.pbData)<br />
                End If</p>
<p>                If Not (entropyBlob.pbData.Equals(IntPtr.Zero)) Then<br />
                    Marshal.FreeHGlobal(entropyBlob.pbData)<br />
                End If<br />
            End Try<br />
        End Function</p>
<p>    End Class</p>
<p>    Sub Main(ByVal args() As String)<br />
        Try<br />
            Dim INfilename As String = args(0) &#8216;Input file with string without CrLf<br />
            Dim OUTfilename As String = args(1) &#8216;Output file<br />
            Dim EncryptedText As String<br />
            Dim TextToEncrypt As String<br />
            Dim EncryptedBlank As String<br />
            Dim BlankToEncrypt As String = Space(256)</p>
<p>            TextToEncrypt = File.ReadAllText(INfilename)</p>
<p>            EncryptedText = DPAPI.Encrypt(DPAPI.KeyType.MachineKey, TextToEncrypt, Nothing, &#8220;psw&#8221;)<br />
            EncryptedBlank = DPAPI.Encrypt(DPAPI.KeyType.MachineKey, BlankToEncrypt, Nothing, &#8220;psw&#8221;)</p>
<p>            File.WriteAllText(OUTfilename, EncryptedText &amp; _<br />
                Right(EncryptedBlank, 1329 &#8211; Len(EncryptedText))) &#8216;Encrypted blank to complete to 1329</p>
<p>        Catch ex As Exception<br />
            While Not (ex Is Nothing)<br />
                Console.WriteLine(ex.Message)<br />
                ex = ex.InnerException<br />
            End While<br />
        End Try<br />
    End Sub</p>
<p>End Module<br />
####################################<br />
Regards.<br />
Dominik</p>
]]></content:encoded>
	</item>
</channel>
</rss>
