Hello Monks.

Just tired using Win32::CryptData. Seeking your help.

Little background. I am not much qualified in Perl.

Working on a windows machine with perl(cygwin). I have created several .rdp files for automatic logon on few remote machines. Need to enter password in this field - "password 51:b:" - in encrypted state.

Picked up the module and used below code stated in module's documentation.

use strict; use Win32::CryptData qw(:flags); my $DataIn = '<mypassword>'; my $DataDescr = 'This is the description'; my $OptionalEntropy = 'mysecret'; my $Reserved = undef; my %PromptStruct = ( PromptFlags => CRYPTPROTECT_PROMPT_ON_PROTECT | CRYPTPROTECT_PROMP +T_ON_UNPROTECT | CRYPTPROTECT_PROMPT_STRONG, hwndApp => undef, Prompt => 'This is the caption' ); my $Flags = CRYPTPROTECT_AUDIT; my $DataOut; my $ret = Win32::CryptData::CryptProtectData( \$DataIn, \$DataDescr, \$Optio +nalEntropy, \$Reserved, \%PromptStruct, $Flags, \$DataOut ); if ($ret) { print "Encrypted data (hex): " . unpack( "H*", $DataOut ) . "\n"; } else { print "Error: $^E\n"; }

I have tried both medium and high security level. It creates a password but that is not working through rdp files.

Someone gave me a self-made .exe in C-Sharp code, which gives an encrypted password and makes that rdp file work properly.

Please help me in understanding whats the problem in perl code, that I can't get correct encryption.

Also, the password given by perl script is very different and much longer than the one given by C-Sharp exe.


In reply to Problem working with Win32::CryptData by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.