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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:30:04+00:00 2026-05-20T07:30:04+00:00

I am writing some C# encrypting that is decrypted by php. They aren’t working

  • 0

I am writing some C# encrypting that is decrypted by php. They aren’t working together very well. The php client has informed me of their configuration (RSSL_KEYGEN_PKCS5_V20, 256 bit AES in CBC mode, RSSL_PAD_ANSIX923). Here is what I put together:

public static byte[] Encrypt(byte[] plainText, string password,
         CipherMode cipherMode, int keySize, PaddingMode paddingMode)
    {
        byte[] salt = new byte[8];
        new RNGCryptoServiceProvider().GetBytes(salt);

        // PKCS#5 V2.0 PBKDF2 keyGenerator (uses default iteration count of 1000) 
        Rfc2898DeriveBytes keyGenerator = new Rfc2898DeriveBytes(password, salt);

        AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
        aes.Mode = cipherMode;
        aes.KeySize = keySize;
        aes.Padding = paddingMode;
        aes.Key = keyGenerator.GetBytes(aes.KeySize / 8);

        // aes.Padding is left default PaddingMode.PKCS7 
        // aes.IV should be automatically set to some random value by .NET 
        // (as described in http://msdn.microsoft.com/en-us/library/5e9ft273(VS.71).aspx) 

        // Overestimate encrypted size requirements 
        byte[] encryptedDataBuffer = new byte[plainText.Length + 32 + 32 + 8];
        MemoryStream encryptedOutput = new MemoryStream(encryptedDataBuffer, true);
        CryptoStream encStream = new CryptoStream(encryptedOutput, aes.CreateEncryptor(),
                                                  CryptoStreamMode.Write);

        encryptedOutput.Write(salt, 0, salt.Length);
        encryptedOutput.Write(aes.IV, 0, aes.IV.Length);
        encStream.Write(plainText, 0, plainText.Length);

        encStream.FlushFinalBlock();
        byte[] encryptedData = new byte[encryptedOutput.Position];
        Array.Copy(encryptedDataBuffer, encryptedData, encryptedData.Length);
        encStream.Close();

        return encryptedData;
    }

I can encrypt and decrypt it on my side, but they cannot decrypt it. Is there something I am doing wrong here? I pass in something like this:

Encrypt(mytext, myPassword, CipherMode.CBC, 256, PaddingMode.ANSIX923);

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-20T07:30:05+00:00Added an answer on May 20, 2026 at 7:30 am

    Using the CryptoServiceProvider did the trick.

     Encoding stringEncoding = new System.Text.UTF8Encoding();
    
            byte[] salt = new byte[8];
    
            new RNGCryptoServiceProvider().GetBytes(salt);
    
            AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
            aes.Mode = cipherMode;
            aes.KeySize = keySize;
    
            aes.Key = stringEncoding.GetBytes(password);
            aes.IV = new byte[aes.IV.Length];
    
            // Overestimate encrypted size requirements 
            byte[] encryptedDataBuffer = new byte[plainText.Length + 32 + 32 + 8];
            MemoryStream encryptedOutput = new MemoryStream(encryptedDataBuffer, true);
    
            CryptoStream encStream = new CryptoStream(encryptedOutput, aes.CreateEncryptor(),
                                                      CryptoStreamMode.Write);
    
            encStream.Write(plainText, 0, plainText.Length);
    
            encStream.FlushFinalBlock();
            byte[] encryptedData = new byte[encryptedOutput.Position];
            Array.Copy(encryptedDataBuffer, encryptedData, encryptedData.Length);
            encStream.Close();
    
            return encryptedData;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an auto update client. It's a very simple app that: 1)
In writing some code today, I have happened upon a circumstance that has caused
Im writing some helper functions for a project im working on. I've always wanted
I'm writing some test cases, and I've got a test case that is using
I'm writing some code (just for fun so far) in Python that will store
I'm currently writing some general purpose .net libraries that contain usual helper classes. For
In writing some image processing routines in Matlab, I found that I don't know
Some streams in c# appear to have a direction in that they are meant
I'm writing a game that will have a lot of information (configuration, some content,
I'm planning on writing some code for encrypting files in javascript locally. For large

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.