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

  • SEARCH
  • Home
  • 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 6867097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:16:01+00:00 2026-05-27T03:16:01+00:00

I was looking at the phpseclib manual for RSA encryption and noticed that the

  • 0

I was looking at the phpseclib manual for RSA encryption and noticed that the public key is used to decrypt the data and private key to encrypt.

From what I have read and understand is the public key ment to encrypt and private key to decrypt hence why it is private, or am I missing something?

Example

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();
//extract($rsa->createKey());

$plaintext = 'Hello World!';
$privatekey = '-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCjfQKsF6ExR/zLUKa2qiIr8jwh9s36z5dXIg+S+iZygO3p8ZNHzJlKj9JhHOnp
8FxObW93JwKeoyd17J6Dep1t2vm9SJt+jAm3psNpM2a1fZVJSMhKJSj/S9cNL8AwL8CuAyioKs4R
XFFuq2ASm0gXd1Y6bKHSzeZ49N8onIwueQIDAQABAoGAAvSZ1YQY1yP6wy8qUF+LfhljMmb8isXx
cbMNLoZEpynDA0lpdPETLVijwDsuVFsSxB0w2GnVX4pKBpT4OZ7AFUqphgv1CpeVGXP+6YISZApb
D3yliPL4fwWYi/ttC2ceMylKhohm+Ol6kxYeUitoiOuft2FzE70SCOxZOU23QsECQQDX9PIru6hr
8p4WBq6D829BB4WHnP7K/pj6gCi/iUXNS8cEHml/mJtgOxbSX8aWFDfJFlCmMcp3/zzw35zM/BJh
AkEAwc18aPgie472UunjlPLKelSlS/D8e2ZPLWbB3xyJcBn7CiCzeavpmQSOeVofrKyJfBb3FQut
VZL3AOMnIX9DGQJBALfsnfQxNxf44jrQJgGraq1vwoHla/tnKtLuI8Y9G33lc/JGFIPfbTVgHee+
OlvHjFtu7fEdptrcPwLG77yFUwECQQCq3HIpzVIBYwoSEXh+kgsnDMdqi3zdglad7XFRNcSJ263y
wN/ajlD1ggnmPSmdv8O6bjjKCjB4OIih9KJEKwHJAkBJAFKDTpAWMXBmSWl95Ibkr+2aU6VUQcVS
jhQbDsAWLNOkIrZsS33SS5kEc3LSl6oLH/Lh3759YLkOONHqFFN4
-----END RSA PRIVATE KEY-----';

$publickey = '-----BEGIN PUBLIC KEY-----
MIGJAoGBAKN9AqwXoTFH/MtQpraqIivyPCH2zfrPl1ciD5L6JnKA7enxk0fMmUqP0mEc6enwXE5t
b3cnAp6jJ3XsnoN6nW3a+b1Im36MCbemw2kzZrV9lUlIyEolKP9L1w0vwDAvwK4DKKgqzhFcUW6r
YBKbSBd3VjpsodLN5nj03yicjC55AgMBAAE=
-----END PUBLIC KEY-----';

$rsa->loadKey($privatekey);
$encrypt_text = $rsa->encrypt($plaintext);

$rsa->loadKey($publickey);
$decrypt_text = $rsa->decrypt($encrypt_text);

echo 'INPUT: '.$plaintext.'<br />';
echo 'ENCRYPTED: '.$encrypt_text.'<br />';
echo 'DECRYPTED: '.$decrypt_text.'<br /><br />';
echo 'PRIVATE KEY: '.$privatekey.'<br /><br />';
echo 'PUBLIC KEY: '.$publickey.'<br />';
?>

Thanks

  • 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-05-27T03:16:02+00:00Added an answer on May 27, 2026 at 3:16 am

    If you encrypt with the private key anyone can decrypt it but only with your public key, thus verifying that it came from you. Of course, if you were doing that you’d probably be better off just signing your message. The PKCS#1 standards does not define signing and encrypting identically and, indeed, the security proof for a signed message is stronger than the security proof for an encrypted message.

    W.r.t. the phpseclib documentation… it was probably just an oversight or a snafu on the developers part. Maybe they realized the mistake but didn’t want to fix it immediately as it wasn’t a code issue and now just keep on forgetting about it? I dunno… I know I can do that. I take more pride in my own code than I do in the documentation.

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

Sidebar

Related Questions

Looking at Facebook I have noticed that images vary in size from 100x100 to
Looking for an example that: Launches an EXE Waits for the EXE to finish.
Looking for a Linux application (or Firefox extension) that will allow me to scrape
Looking for opinions on if OpenCV could be or has been used to detect
Looking through the achievement list for Visual Studio 2010, it says that there is
Looking for an equivalent container class that matches to C#'s Arraylist collections class. Is
Looking for a better way of extracting a number from the last line in
Looking at the list of annotations in FindBugs 2.0 , I see that a
Looking at a Get-WebFile script over on PoshCode, http://poshcode.org/3226 , I noticed this strange-to-me
Looking for web service that download a webpage (we'll provide the URL), normalize it

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.