0

I am having some troubles with decrypting zip archive via openssl in php.

Thats how i encrypt it with my public key.

public function encrypt($data) {
        openssl_public_encrypt($data, $encrypted, $this->pubKey);

        return chunk_split(base64_encode($encrypted));
    }

Encryption output looks like this:

T5Nu3gGqCnwFhBoctx0D1bOvrBg9VfKNJaVz5RSu4OBsKI2qBdw1sZ4YQNC8ya3xU/tvpcTtw/vd LKZeKaFZloPP49hu9uRX7+rJYegVHHLKBdP0JX380mmJCq+4kj1R3gt4l4zzBGuvEZMQnSffOgdR hdao0DcSU0R2feOKkyuIy9NVxtmX9iXVGmOalyy0s4azk9mD5KnHcKIYgJG7YCyAr97lX6A7MKMi xq9/hpvLhdQa5cZH6f1eXoIFx9uRSIaKdeKmZzHPVUPOVnqlHQuhtUE+Of/RnWYYKoS280TUROKV fk7jepF+w3wxQ1yrYLDPyglWBCjyaHQbdDTB7w==

Then I am trying to decrypt my zip archive back.

public function decrypt($data) {
        openssl_private_decrypt(base64_decode($data), $out, $this->prvKey);

        return $out;
    }

I am just getting path of zip archive, something like

C:\OpenServer\domains\project\src\AppBundle\Command/../../../backup/2016_04_05_full.zip

How should i decrypt encrypted zip archive file?

thanks!

Scott Arciszewski
  • 33,610
  • 16
  • 89
  • 206
Tigran
  • 633
  • 4
  • 17
  • 26
  • openssl_public_encrypt encrypts the supplied $data, in this case it is the zip file path. To encrypt an entire file requires a bit more work. Here's a place to start http://stackoverflow.com/questions/30742390/encrypting-large-files-in-php-with-openssl – dbugger Apr 05 '16 at 18:31
  • @dbugger That shows just the symmetric encryption part though. You'd need to generate a random data key and encrypt that with the public key using the function above (i.e. create a hybrid cryptosystem). – Maarten Bodewes Apr 05 '16 at 21:45

0 Answers0