Skip to content
Advertisement

how to decrypt each hash string from a text file using openssl_decrypt and output each line

i have a text.txt file which contains a list of encrypted passwords, each line starts with the name then a seperating symbol and then the encrypted passoword. the list looks like-

instagram-&&-aHJK7y9894ds==
facebook-&&-dKBHJ&^(8*==
somesite-&&-djahJHl*(&==

now i want to decrypt password from each line using the key which is included in the code. to seperate the hash and name i use php explode() function and “-&&-” as the seperator which gives me this array as output

code to convert text to array of encrypted password-
<?php

$data = <<<EOT
instagram-&&-aHJK7y9894ds==
facebook-&&-dKBHJ&^(8*==
somesite-&&-djahJHl*(&==
EOT;

$lines = explode(PHP_EOL, $data);
foreach($lines as $line){
    var_dump(explode('-&&-', $line));
}

the output looks like-

array(2) {
  [0]=>
  string(9) "instagram"
  [1]=>
  string(14) "aHJK7y9894ds=="
}
array(2) {
  [0]=>
  string(8) "facebook"
  [1]=>
  string(12) "dKBHJ&^(8*=="
}
array(2) {
  [0]=>
  string(8) "somesite"
  [1]=>
  string(12) "djahJHl*(&=="
}

Now the main question is how do i use openssl_decrypt() in combination with this to get each line decrypted.

Advertisement

Answer

So i researched a lot about this problem tried the solution provided by @Edoldin in my question. I searched the problem in PHP official documentation- Here and OPENSSl documentations here- Here

I got the solution by modifing and using this code-

$lines = explode(PHP_EOL, $data);
foreach($lines as $line){
    $parsed=explode('-&&-', $line)
    echo "user= ".$parsed[0]." pass= "
         .openssl_decrypt( eng_data($key, $parsed[1]) )
}

This is the Final solution i am using. Thanks.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement