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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:51:51+00:00 2026-05-28T20:51:51+00:00

This article explains why string Encoding shouldn’t be used to round-trip the cipher text.

  • 0

This article explains why string Encoding shouldn’t be used to round-trip the cipher text. However, if I try using recommended Convert.ToBase64String, I get an exception if the original string is not packaged with 4-byte blocks. In the following example, the original string doesn’t work, but just “Zoidberg” does, since it’s 8 bytes long (that are packaged into a 6-byte array when Convert.ToBase64String is used).

As promised in the article, if I use any string Encoding, I get “Bad Data” error when decrypting the value back. So how should the original string be fed into the crypto APIs as a byte array?

string text = "Zoidberg is important!";
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
// This throws FormatException: "The input is not a valid Base-64 string as it 
// contains a non-base 64 character,  more than two padding characters, 
// or a non-white space character among the padding characters"
byte[] cipherText = provider.Encrypt(Convert.FromBase64String(text), false);
string plainText = Convert.ToBase64String(provider.Decrypt(cipherText, 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-05-28T20:51:52+00:00Added an answer on May 28, 2026 at 8:51 pm

    I think you were mislead by that article.
    It does not make sense to convert from string -> byte[] --> encrypted byte[] --> string, which is what that article is showing you to not do.

    Presumably, you want to go string -> byte[] -> encrypted byte[] -> (network, whatever) -> encrypted byte[] -> byte[] -> string. It’s fine to use Encoding to convert the string to bytes in this manner.

    I don’t know why the article you linked would warn you against taking the encrypted bytes and converting that directly back to a string. Seems silly.

    You say you’re trying to round-trip the ciphertext, so I would do so with byte arrays containing the encrypted bytes of your string and forget about base-64 encoding.

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

Sidebar

Related Questions

This article explains how to use Zend in Codeigniter. http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/ I am using XAMPP
I ma using this article which explains how to use password strength validator. The
The Java Virtual Machine supports several garbage collection strategies. This article explains them. Now
I've found this MSDN article that explains how to monitor processes and services with
This Linux Magazine article http://www.linux-mag.com/id/792 explains the difference in the way threads are implemented
This article on MSDN states that you can use as many try catch blocks
this article suggests you can use Color c = Color.decode(FF0096); however this understandably throws
I guess many people already read this article: Using your own SQLite database in
In this article , the author explains rebasing with this diagram: Rebase: If you
I recently came across this article which explains how to use HTML5 tags in

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.