Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:36:00+00:00 2026-06-16T03:36:00+00:00

I saw this code: <?php class MyEncryption { public $pubkey = ‘…public key here…’;

  • 0

I saw this code:

<?php
class MyEncryption
{

    public $pubkey = '...public key here...';
    public $privkey = '...private key here...';

    public function encrypt($data)
    {
        if (openssl_public_encrypt($data, $encrypted, $this->pubkey))
            $data = base64_encode($encrypted);
        else
            throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?');

        return $data;
    }

    public function decrypt($data)
    {
        if (openssl_private_decrypt(base64_decode($data), $decrypted, $this->privkey))
            $data = $decrypted;
        else
            $data = '';

        return $data;
    }
}


?>

What are samples of public_key? What kind of public key should be put on $pubkey? Should it be base_64encoded or not? How do I generate one?

I added:

$privKey = openssl_pkey_new();

And all I got is $privKey==false

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:36:01+00:00Added an answer on June 16, 2026 at 3:36 am

    The keys have to be generated together, as the public key is the “non-secret” key that can encrypt information so that only the private key is able to decrypt it. This is an example of Public-key cryptography.

    If openssl_pkey_new fails (it will not return the key itself, only a resource that you can use to retrieve the actual keys), see the examples and links to alternatives in the comment section of the manual page.

    And no, the keys should not base64-encoded. This is only done to the encrypted data in your methods. The reason that this is done in the class is probably because the original author wanted to transfer the encrypted data through some sort of non-binary-safe environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just saw this code while studying the wordpress source code (PHP), You can
I saw this today in some PHP code: $items = $items ?: $this->_handle->result('next', $this->_result,
I saw this code somewhere without the PHP backend for it and have wondering
I was reading the PHP manual for mysqli_stmt_bind_result and saw this code in the
I read php document and I saw this: class foo{ var $bar = 'I
I saw this code in a PHP book (PHP architect, ZEND PHP 5 Certification
I'm reading up on php design patterns, and I saw this code: <?php require_once(DB.php);
I saw this code snippet during our lab and it actually compiles in MSVC2008
I saw this code snippet const volatile int * volatile * const X; but
I saw this code in http://www.cise.ufl.edu/~manuel/obfuscate/obfuscate.html (http://www.cise.ufl.edu/~manuel/obfuscate/savastio) website.But this code is very very crazy.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.