Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: Problem working with Win32::CryptData
by gurpreetsingh13 (Scribe) on Jun 17, 2013 at 14:36 UTC
    I believe there are 2 methods for the same - either directly touch the method CryptProtectData or alternatively, study the algorithm and make a DES encryption yourself using Crypt::DES module