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 6608347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:36:00+00:00 2026-05-25T19:36:00+00:00

I need to encrypt and decrypt a string. I can’t use the hash because

  • 0

I need to encrypt and decrypt a string. I can’t use the hash because the decrypted string must be readable. I know about mcrypt but i was looking something that uses a certificate file to encrypt and decrypt.

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-25T19:36:01+00:00Added an answer on May 25, 2026 at 7:36 pm

    You can use a public/private key through openssl and is pretty simple once you use it once or twice

    function encryptString($clearText)
    {
      $keyFile=fopen("public.pem","r");
      $publicKey=fread($keyFile,8192);
      fclose($keyFile);
    
      openssl_get_publickey($publicKey);
      openssl_public_encrypt($clearText,$cryptText,$publicKey);
      return(base64_encode($cryptText));
    }
    
    function decryptString($cryptText)
    {
      $keyFile=fopen("private.pem","r");
      $privateKey=fread($keyFile,8192);
      fclose($keyFile);
    
      openssl_get_privatekey($privateKey);
      $binText = base64_decode($cryptText);
      openssl_private_decrypt($binText,$clearText,$privateKey);
      return($clearText);
    }
    

    To generate a keypair, a brief guide is http://en.wikibooks.org/wiki/Transwiki:Generate_a_keypair_using_OpenSSL

    In short

    openssl rsa -pubout -in private.pem -out public.pem
    

    Update

    @keepwalking asked below how to do this from the command line and @vstm responded with a great link http://www.devco.net/archives/2006/02/13/public_-_private_key_encryption_using_openssl.php.

    To summarize that page, once you have keys created, you can encrypt a text file file.txt and output it to file.ssl by using the following command.

    openssl rsautl -encrypt -inkey public.pem -pubin -in file.txt -out file.ssl
    

    To decrypt file.ssl to another file decrypt.txt, you can use the following command.

    openssl rsautl -decrypt -inkey private.pem -in file.ssl -out decrypted.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a project I'm working on, I need to encrypt and decrypt a string
Can any one please let me know the way, how can i encrypt/decrypt a
How can I encrypt/decrypt with fuzzy tolerance? I want to be able to use
how can i encrypt/decrypt string with cer file and private key in java do
I need fast and simple way to encrypt/decrypt a lot of String data. I
I need to encrypt and decrypt a querystring in ASP.NET. The querystring might look
I need to encrypt a string on the iPhone and send it to a
I'm in a situation where I need to encrypt / decrypt a file of
Does anyone know of a good way to encrypt and decrypt strings using VB6
I need to encrypt and decrypt pdf files. Is there a free or low

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.