Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

Scripting Games 2007 Advanced PowerShell Event 7

For Event 7 I did the Following Script, using DPAPI (only decryptable by same user on same Computer ) for Encrypting :

 

PARAM ($mode)
Switch ($mode) {
 
    'e' {
        $ss = ConvertTo-SecureString -string ( [System.IO.File]::ReadAllText("$(pwd)\alice2.txt")) -AsPlainText -Force
        convertfrom-securestring $ss | out-file  Encoded.txt -encoding ascii
    }
 
    'd' {
        $ss =ConvertTo-SecureString (gc "$(pwd)\Encoded.txt")
        $ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ss)
        [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($ptr)
    }

    default {write-warning "no E of D parameter given"}

}

 It looks like this :

 

PoSH> .\Event7.ps1 e                                                                                                    
PoSH> gc Encoded.txt                                                                                                    
01000000d08c9ddf0115d1118c7a00c04fc297eb010000002ad0cc80f3b89843bff337cd423e1a250000000002000000000003660000a8000000100 
00000596340ac3da1d95deddbfc3628cadcbf0000000004800000a00000001000000071bd5d572e705f37e78eedfe97173061b00500003fe59eccd9 
7acf7ca30a46057c330cab229740c60507a8563f38eb5de46f608750c4638129e735e6d56e4329b1aaa4318c2a2fcf189159a75104f6cac3a6fa58e 
be66e6aa1426d392cdf804e86e2bb8e797137d9ec282438eb2d4a7549639194f2c2224dcee9b0f01582365486f7e46a28dbf3e326aba034938f1d0d 
7338b32f74cd648098b61a7ae7a0efc1753431941098fe939854f2cd09ae92f29d593527ea6fcbcde7e30c462ea6efd285d0a92b3766dfeaa420e05 
7d0f5589f40d353f782d40935938d7b1f33354ec8874fc4b008999805e1ce101efa7613cbbda29007207d33650d8b9cdb86538707cbf0a6861681df 
9301872e4cd8cfddce72e0e6156d984270a2d28a39b1b47a4a01cea5adc0230053f80d8d227b528e1b812a5ece60fac762cdd4545228d7789167b50 
4902f488bf418943349149b827ef86ecfa329619884ba3459693fc7e0d1e31421c2e461d838a2ef5be44570dc9108a5512c947f0bee0f80cf2a4160 
d37e2f32edd11b5838d17f703d80bdef26fa8b06b95e6c579943a3cf43f5ff24e579da24762d4882453a623107d8d6c1ef890429ccf49c019b9281b 
23ae6a8482a9832f315bdd25885f4aa7dd343a67ea2a0aaef479bc455221ee2fa46a4e8652951202faca39506b86fc42ca0e68feaad8455f734215a 
05cedacc95fe69e9c4a0e605d7968d520ec2ae70caba1e25ed9f75762a5caef1f0fc202d1ca8a608cdb6a0cd01cfca224dff2700c02be554a19aeff 
b07c6720dad52422464f3881eaefdd867a2b5e491f8bf4c779661106d7001057954e1a6a5902900df4ccbf688346182d8043bfd32bfde2e07ca63d6 
172859d2e13b4d398b3d9ef96e8b68abc321eaed79bdc58d8e4213a81319fcab8f22e46c33441c3ebcc4af0a167636161b3afd698ed30aa90b9ed90 
204db34ef42c9ec660bdca00b786d3e3dc9c055b72415a5578b7ffdfb6f1b1d9bb23047981dd77e8b2b5c80db47bf3d8fb69d041be61256d27dfcb9 
5680894efb278ff65d883c96e82b38f361104b183e9f64d4630824775be53d086257a6546532fd6d690abb439f948078edb89289618d02aa3e4dfd0 
37301f5c255551db3de42443e79211362dada9f0f487a5053a37eab38b8d8e3b723dffcf2592e055cdaa5acf5f943083a7432650803391f821b95aa 
0b0b41e90a6938626c4daca07be041fe99706781341f7496aaeda754655e07deace8708154c4e8279a6667c782ddb186657a72bb6748d95f468f6c4 
924d0567fa09e6cda139d356939ae6b209316fbc485780714acfd09550c75953ecfc37be32ffc5066f025bbb1bb1a31d4a8ccf2a152736bee35b925 
6876d91862f3d5da82ec41acb29b86c7f14180d74a88ddbc52207e0e4de427c04f0364d728f465f9c870792d2acdea5a73961c60a08c14e82c8c21b 
e89963583e6f739309a0d8ab41bc10bb29d4b82475ebc7918192f777191c0f3948d11dab57a60f141aad8f7e9872cf7d904a19d83caaeb4dd092ca9 
c2a94ef177d1b948fd7c8b31194f95a80e312cc2a55ef5eb0bf727f600ce10706d13afd42bd58da2a156a05fee2622b5c6da2e30cddcaa58d2026d7 
06a93870b294341e8158dd5758bc92a6dddedde4f74c5660924225f88aba1e4c8ed0cbbca25e075257fd512aaa73c5a1aeb74d08d95306616e0ef6b 
41689857393a60b0dc73db63ceadc421f7bfc4fe36a46a90c9229dfbf2852458529b22a8c29ffeaa7dad1ac43b13d3038f8e8f86f553b2086db2213 
c59fb25a048210374a495bf748d20bfc19d88952d95c0d9ed1ef0fa32f2901664b1af6f544b9b32b978183b92960e396dbdd453141105553b05a10e 
cd87472c23806eff9d8fbce8c0c03e63d12a6e7571c48030c84c565a8a06b7a2e90c0555592c74af1b0ea17a5e5b08e0517f1a0a97714413f6877c3 
f42324fbd13647136e332a73a8904c02ccbae4aad12e21659cf960932358b09cb202765daf5db2f881eaab58f1f5a63954c4bfbd7dbf2d0deefaee0 
dcb3afd0eb0d6d29c9f3ad5340f74f9745345ad169be5f14000000ee0f0b705f69c1813acc5140ba0cf651eb09063e                          
PoSH> .\Event7.ps1 d                                                                                                    
Curiouser and curiouser!' cried Alice (she was so much surprised, that                                                  
for the moment she quite forgot how to speak good English); 'now I'm                                                    
opening out like the largest telescope that ever was! Good-bye, feet!'                                                  
(for when she looked down at her feet, they seemed to be almost out of                                                  
sight, they were getting so far off). 'Oh, my poor little feet, I wonder                                                
who will put on your shoes and stockings for you now, dears? I'm sure                                                   
_I_ shan't be able! I shall be a great deal too far off to trouble myself                                               
about you: you must manage the best way you can; --but I must be kind to                                                
them,' thought Alice, 'or perhaps they won't walk the way I want to go!                                                 
Let me see: I'll give them a new pair of boots every Christmas.'                                                        
PoSH> 

 

 

For more info (and how to use Rijndael encreption using Password ) see also this entry's on my old blog : 

/\/\o\/\/ PowerShelled: Get-credential and Decrypting a ...

/\/\o\/\/ PowerShelled: More on Cryptograpy and MSH

Enjoy,

 

Greetings /\/\o\/\/

Published Wednesday, February 21, 2007 11:12 AM by admin

Comments

# re: Scripting Games 2007 Advanced PowerShell Event 7

Mine ;)

param([string]$mode)

if ($mode -eq "e"){get-content "Alice2.txt" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Set-Content "encoded.txt"}

elseif($mode -eq "d"){get-content "encoded.txt" | ConvertTo-SecureString | %{[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($_))}}

Wednesday, February 21, 2007 10:16 PM by Xaegr

# re: Scripting Games 2007 Advanced PowerShell Event 7

@ Xaegr

Lol,

Also used my old blog for reference on this event ?

Greetings /\/\o\/\/

Thursday, February 22, 2007 5:36 AM by MoW
Anonymous comments are disabled