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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:21:05+00:00 2026-06-12T02:21:05+00:00

I am encryption/decryption some plain text using following code. private static string EncryptionKey =

  • 0

I am encryption/decryption some plain text using following code.

private static string EncryptionKey = "@#$%^&*()2343";    
private static byte[] Salt = Encoding.ASCII.GetBytes(EncryptionKey.Length.ToString()); 

public static string EncryptIt(string Input)    
{    
    RijndaelManaged Cipher = new RijndaelManaged();    
    byte[] TextByteArray = Encoding.Unicode.GetBytes(Input);    
    PasswordDeriveBytes Key = new PasswordDeriveBytes(EncryptionKey, Salt);    

    using (ICryptoTransform Transform = Cipher.CreateEncryptor(Key.GetBytes(32), Key.GetBytes(16)))    
    {        
        using (MemoryStream MS = new MemoryStream())    
        {    
            using (CryptoStream CS = new CryptoStream(MS, Transform, CryptoStreamMode.Write))    
            {    
                CS.Write(TextByteArray, 0, TextByteArray.Length);    
                CS.FlushFinalBlock();    
                return Convert.ToBase64String(MS.ToArray());    
            }    
        }    
    }    
}    

public static string DecryptIt(string Input)    
{    
    RijndaelManaged Cipher = new RijndaelManaged();    
    byte[] EncryptedByteArray = Convert.FromBase64String(Input);    
    PasswordDeriveBytes Key = new PasswordDeriveBytes(EncryptionKey, Salt);    

    using (ICryptoTransform Transform = Cipher.CreateDecryptor(Key.GetBytes(32), Key.GetBytes(16)))    
    {    
        using (MemoryStream MS = new MemoryStream(EncryptedByteArray))    
        {    
            using (CryptoStream cryptoStream = new CryptoStream(MS, Transform, CryptoStreamMode.Read))    
            {    
                byte[] TransformedText = new byte[EncryptedByteArray.Length];    
                int Count = cryptoStream.Read(TransformedText, 0, TransformedText.Length);    
                return Encoding.Unicode.GetString(TransformedText, 0, Count);    
            }    
        }    
    }    
}    

In most of the cases, this code works fine. However in some cases when I try to decrypt the encrypted text, I get following exception when byte[] EncryptedByteArray = Convert.FromBase64String(Input) is called in DecryptIt methods.

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.

Any idea what could be causing this exception. What I am finding more puzzling is that why this excpetion is not thrown on every cases and only few cases.

EDIT :
Sample Input to DecryptIt method that throws exception is below. Please note that I have changed the value of EncryptionKey variable in my sample above.

oaOQ6qWWDwWby3C04N7HJAiqQgILBifqdHq4OQ5KDDRA3F2ZlBITu31a8mJJQ8sKn4g3vODFEJbigtNZozv6ockAdsDChhHwaaLL4l8MJPKbV1EiUE3rL30y+xHz/S1a8mJJQ8sKn4g3vODFEJbigtNZozv6ockAdsDChhHwaaLL4l8MJPKbV1EiUE3rL30y+oz/eR9OzXn+3Lepo0tRqH5BsfvEtJ/IcqRu3gJiIBTMAM0TmVxa2EZSj2mn6jZlgvlOEFCWzNKS3R9OzXn+In1br14venJmpApXyt930khz35UE5BtWn3Fq7jyer6mY2l60P/cI4z

  • 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-12T02:21:07+00:00Added an answer on June 12, 2026 at 2:21 am

    Your sample deconverts perfectly with 2 extra ‘=’ at the end.
    So somewhere they are lost in transport.

    The ecrypted text is sent via email in a http link.

    So that involves both URL and HTML encoding? Plenty of room for an error.

    Run a test with a small string ending in ==.

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

Sidebar

Related Questions

I wrote the following code for text file encryption and decryption. The encryption process
I've written Encryption/Decryption methods using the RC2CryptoServiceProvider in C# and for some reason, I
Unfortunately, I have some code that does this: byte[] plainText = System.Text.Encoding.ASCII.GetBytes(ClearText); var btcipherText
I am interested if it's possible to do string encryption/decryption using Excel Visual Basic
I need to digitally sign some text in python using a private key stored
Where can I find some simple sample code for public key encryption and decryption
I am trying to encrypt some plain text with a public key using RSA_public_encrypt(),
I was working on some encryption/decryption algorithms and I noticed that the encrypted byte[]
I would like to embed some C# .Net code that does some simple Encryption/Decryption
I am using RijndaelManaged to make a simple encryption/decryption utility. This is working fine,

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.