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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:26:48+00:00 2026-05-27T02:26:48+00:00

If I give the decrypter RSAalg2.Decrypt(encryptedData, false); it works fine but I need to

  • 0

If I give the decrypter RSAalg2.Decrypt(encryptedData, false); it works fine but I need to convert the encrypted data (byte array) to a string then back to a byte array.

I’ve tried ASCIIEncoding, UTF-8 rather than Unicode with no luck. I’d appreciate any help I can get. Thanks

UnicodeEncoding ByteConverter = new UnicodeEncoding();

string dataString = "Test";

byte[] dataToEncrypt = ByteConverter.GetBytes(dataString);
byte[] encryptedData;
byte[] decryptedData;

RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider();

Console.WriteLine("Original Data: {0}", dataString);

encryptedData = RSAalg.Encrypt(dataToEncrypt, false);

Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData));

String XML = RSAalg.ToXmlString(true);
XmlDocument doc = new XmlDocument();
doc.LoadXml(XML);
doc.Save(Environment.CurrentDirectory + "\\key.xml");

RSACryptoServiceProvider RSAalg2 = new RSACryptoServiceProvider();

StreamReader sr2 = File.OpenText(Environment.CurrentDirectory + "\\key.xml");
string rsaXml2 = sr2.ReadToEnd();
sr2.Close();

RSAalg2.FromXmlString(rsaXml2);
string s = ByteConverter.GetString(encryptedData);
byte[] se = ByteConverter.GetBytes(s);
decryptedData = RSAalg2.Decrypt(se, false);

Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
  • 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-27T02:26:49+00:00Added an answer on May 27, 2026 at 2:26 am

    The code below demonstrates what you are after.

        [Test]
        public void RsaEncryptDecryptDemo()
        {
            const string str = "Test";
            var rsa = new RSACryptoServiceProvider();
            var encodedData = rsa.Encrypt(Encoding.UTF8.GetBytes(str), false);
    
            var encodedString = Convert.ToBase64String(encodedData);
            var decodedData = rsa.Decrypt(Convert.FromBase64String(encodedString), false);
            var decodedStr = Encoding.UTF8.GetString(decodedData);
    
            Assert.AreEqual(str, decodedStr);
        }
    

    The trick is to convert your byte array into a form that can be represented as a string. To that effect, the example above utilizes Base64 encoding and decoding.

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

Sidebar

Related Questions

I used Rijndael algorithm to encrypt/decrypt my data. But it is not FIPS compatible.
i want to Encrypt and Decrypt data in J2ME using AES Algorithm with bouncy
My script uses openssl_private_decrypt() to decrypt a string encrypted with RSA in another program.
I understand that private and public keys are mathematically related and data encrypted with
I have AES encrypted data stored in the database using php mysql. Which I
Can anyone give me an example for encrypt and decrypt an image using .net
I would like to give customers a random-looking order number but use 0, 1,
Give a linear-time algorithm to test whether a tree has a perfect matching, that
Give a base class Base , I want to write a method Test, like
Give an Image component, how can I tell the size [width and height] of

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.