Powershell running Java Script to Encrypt Password -




we have number of lanier mfps use scan-to-folder option allow people documents, , starting implement more security measures on ad passwords use forcing password reset.

unfortunately, laniers use proprietary encryption passwords. i've managed functional java command encrypt passwords format. problem i've been encountering have encoded password powershell pass scanner.

i can run java command through command line, can't pass encrypted password powershell string printer accept (it needs in base64). if pass encoded password powershell, run through powershell's base64 creation process, is, obviously, changed scanner use it.

what need determine whether there's way me take following command line command, , run in powershell, provide me output can pass printer.

java -cp ./commons-codec-1.10.jar;. cdm.gwpwescharacterencoding %pass% "gwpwes002" 

the java command outputs base64 string based on following line:

return new string(base64.encodebase64((byte[])encrypt)); 

as example, if pass text 'test' that, string "hvhcmtla25mehvnchq=="

this useless me, though, can't powershell pass through printer, , if encode base64 powershell, comes out "mgboahmawgbtadkaegbjadiaqgbxaguamabkahgawgbyaggabgbiag0amab3ad0a".

can help?

revised code after assistance:

$pass1 = "test" $path = "c:\test\printercreds" $encode = "gwpwes002"  cd $path  $pinfo = new-object system.diagnostics.processstartinfo $pinfo.filename = 'java' $pinfo.arguments = "-jar .\commons-codec-1.10.jar cdm.gwpwescharacterencoding $pass1 $encode" $pinfo.useshellexecute = $false $pinfo.redirectstandardoutput = $true $pinfo.redirectstandarderror = $true $process = new-object system.diagnostics.process $process.startinfo = $pinfo [void]$process.start() $passsec = $process.standardoutput.readtoend() $process.waitforexit()  write-host $passsec 

please try this. encoding gwpwes002. found old java version here. https://www.dropbox.com/s/3324g84x0l4bnon/gwpwescharacterencoding.java?dl=0

there weakness in "encoding". front part of encoding random padding. pack part actual string stored. running script on same string few times points out error.

encodegwpwes002 -code "a" 

generated hashes

np6ewfiewj6ewa==

np6ewj5ywfiewa==

wfienlhynliewa==

nlhynp5ynp6ewa==

nliewfiewj6ewa==

everything until ewa== random padding mean "ewa==" == "a"

same "aaaaaaaa"

np5ywj5ynliewfhywfhywfg=

np5ynp6ewj6ewfhywfhywfg=

nlienp6ewj6ewfhywfhywfg=

wj5ywj6enliewfhywfhywfg=

meaning

"ewfhywfhywfg=" "aaaaaaaa".

the password provided "test", example of manipulation :

hvhcmtla25mehvnchq== "test" :: 29 88 92 154 217 90 219 153 158 29 89 220 29

hvhcmtla25mefvnchq== "test" :: 29 88 92 154 217 90 219 153 158 21 89 220 29

here powershell have translated below

#private static string encodegwpwes002(string code, int codesize) { function encodegwpwes002([string]$code, [int]$codesize = 0){     #byte[] protectcode;     [byte]$protectcode | out-null     #try {     try{         #protectcode = code.getbytes("utf-8");         $protectcode = [system.text.encoding]::utf8.getbytes($code)     #}catch (throwable e) {     }catch{         #return null;         return $null     #}     }     #int encodesize = codesize;     [int]$encodesize = $codesize     #if (protectcode.length >= codesize) {     if(($protectcode.length) -ge $codesize){         #encodesize = protectcode.length + 9;         $encodesize = ($protectcode.length) + 9     #}     }     #byte[] simple = new byte[encodesize];     [byte[]]$simple = new-object byte[] $encodesize     #int diffusecnt = 0;     [int]$diffusecnt = 0     #int simplecnt = 0;     [int]$simplecnt = 0     #if (protectcode.length < encodesize - 1) {     if(($protectcode.length) -lt ($encodesize - 1)){         #for (diffusecnt = 0; diffusecnt < encodesize - 1 - protectcode.length; ++diffusecnt) {         for($diffusecnt = 0; $diffusecnt -lt ($encodesize - 1 - ($protectcode.length)); $diffusecnt++){             #simple[diffusecnt] = (byte)(math.random() * 25.0 + 97.0);             $simple[$diffusecnt] = [byte] (get-random -maximum 0.9 -minimum 0.1) * 25.0 + 97.0         #}         }     #}     }     #simple[diffusecnt++] = 122;     $simple[$diffusecnt++] = 122     #for (simplecnt = diffusecnt; simplecnt < protectcode.length + diffusecnt; ++simplecnt) {     for($simplecnt = $diffusecnt; $simplecnt -lt ($protectcode.length) + $diffusecnt; $simplecnt++){         #simple[simplecnt] = protectcode[simplecnt - diffusecnt];         $simple[$simplecnt] = $protectcode[$simplecnt - $diffusecnt];     #}     }     #byte[] encrypt = new byte[simplecnt];     [byte[]] $encrypt = new-object byte[] $simplecnt     #for (int = 0; < simplecnt; ++i) {     for([int]$i=0; $i -lt $simplecnt; $i++)  {           #byte work = 0;         [byte]$work = 0         #work = (byte)((simple[i] & 192) >>> 6 | (simple[i] & 63) << 2);         $work = [byte](($simple[$i] -band 192) -shr 6 -bor ($simple[$i] -band 63) -shl 2)         #encrypt[i] = (byte)((work & 240) >>> 4 | (work & 15) << 4);         $encrypt[$i] = [byte](($work -band 240) -shr 4 -bor ($work -band 15) -shl 4)     #}     }     #return new string(base64.encodebase64((byte[])encrypt));     return [string]([system.convert]::tobase64string([byte[]]$encrypt)) #} }  encodegwpwes002test -code "test" 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -