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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:25:52+00:00 2026-05-24T10:25:52+00:00

I tried to encrypt data using this function in PHP and decrypt it with

  • 0

I tried to encrypt data using this function in PHP and decrypt it with the other function in C#. But I don’t get the same string.

//php function
    public function onCrypt($text)
    {   
    $key=md5('DFDFDFDFDFDFDFDFDFDFDFDF',true);

    $crypttext = urldecode(trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$key, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND))));

    $text_crp =base64_encode($crypttext);


    return $text_crp;
            }

//c# function

//public static void DecryptFile
Parameters :
strKey : the key choosed in decryption .
PathPlainTextFile : path of the crypted file
PathPlainTextFile : the original file decrypted.

public static void DecryptFile(string strKey, string pathPlainTextFile, string pathCypheredTextFile)     
  {  

//crypt key with md5 function           
System.Security.Cryptography.MD5 alg = System.Security.Cryptography.MD5.Create();
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
byte[] md5val = alg.ComputeHash(enc.GetBytes(strKey));


StreamReader fsPlainTextFile = File.OpenText(pathPlainTextFile);    
FileInfo t = new FileInfo(pathCypheredTextFile);
StreamWriter Tex =t.CreateText();
string input = null;
while ((input = fsPlainTextFile.ReadLine()) != null)
{


        byte[] cipheredData = Convert.FromBase64String(input);

           RijndaelManaged rijndaeld = new RijndaelManaged();

            // define the used mode
            rijndaeld.Mode = CipherMode.ECB;

            // create the cipher AES - Rijndael
            ICryptoTransform decryptor = rijndaeld.CreateDecryptor(md5val,null);

             // Write the ciphered data in  MemoryStream
            MemoryStream ms= new MemoryStream(cipheredData);
            CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);

                 // Insert  the ciphered data in a byte array
               byte[] plainTextData = new byte[cipheredData.Length];

            int decryptedByteCount = cs.Read(plainTextData, 0, plainTextData.Length);

            ms.Close();
            cs.Close();


   // Insert  the ciphered data in string encoded on Base64         
Tex.WriteLine (Encoding.UTF8.GetString(plainTextData, 0, decryptedByteCount));





}

Tex.Close();    


    }
  • 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-24T10:25:54+00:00Added an answer on May 24, 2026 at 10:25 am

    At a quick glance, you’re not supplying an IV to the C# decryptor:

    ICryptoTransform decryptor = rijndaeld.CreateDecryptor(md5val, null);
    

    I’m not familiar with php, but it looks like you created an IV when you encrypted the content. You’ll need to have that same IV to decrypt it in the C# code (you’d need the same IV to decrypt it even if you were doing the decryption through php).

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

Sidebar

Related Questions

I tried to encrypt an array then decrypt it back to string by calling
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
I need to encrypt a string using MySQL's AES_ENCRYPT function, then attach that encrypted
Does anyone know why this php encrypt/decrypt is not working? We used this in
I need fast and simple way to encrypt/decrypt a lot of String data. I
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
Tried a bunch of things but I can't get it to work consistently amid
I want to encrypt/decrypt lots of small (2-10kB) pieces of data. The performance is
I'm trying to encrypt and decrypt a file stream over a socket using RijndaelManaged,
I am trying to encrypt data using AES (ECB) .How can i do it

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.