1

I generated a key pair (public and private), and from console by:

openssl smime -encrypt -aes256 -in backup.sql -binary -DEM -out outform backup_encrypted.sql public_key.pem

I encrypt the file correctly. Sql, as I can do this with php? I've tried several and nothing Functions

Here I leave one of them.

$data=file_get_contents("backup.sql");
$key=file_get_contents("public_key.pem");
openssl_public_encrypt($data,$output,$key);
echo $output;

$output returns nothing .. Thank you.

1
  • Before encrypting a file.. Are you using a two way encryption? one to passively encrypt so it cannot be read, and another to decrypt so it can be read? Commented May 23, 2013 at 8:54

2 Answers 2

2

Please take a look at the manual, you have to give the path of the public key:

$data=file_get_contents("backup.sql");
$key="file://path/to/public_key.pem";
openssl_public_encrypt($data,$output,$key);
echo $output;
Sign up to request clarification or add additional context in comments.

3 Comments

not work.. openssl_public_encrypt works with large text files?
and got to see the record and get this .. what I was saying .. is there any solution? "error:0406B06E:rsa routines:RSA_padding_add_none:data too large for key size"tt
@AitorChicharro What if you tried: openssl_public_encrypt($data,$output,$key, OPENSSL_NO_PADDING); ?
1

you can you file_get_contents(), as example:

$data=file_get_contents("backup.sql");
$key= file_get_contents('public_key.pem');
openssl_public_encrypt($data,$output,$key);
echo $output;

I checked this snippets and its working.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.