473,383 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Encrypted in C# and decrypted in PHP

1
Hi all,

I am working on the php program to decrypted the password which is encrypted by C#. However, the codes show below could not work. Any ideas?

C# coding:
Expand|Select|Wrap|Line Numbers
  1. private static String password = @"abc";
  2.         private static String saltV = @"123";
  3.         private static String hashAlgorithm = "SHA1";
  4.         private static int passwordIterations = 2;
  5.         private static String iv = @"123456789123456";
  6.         private static int keySize = 256;
  7.  
  8.          public static string Encrypt(string text)
  9.         {
  10.             byte[] ivBytes = Encoding.ASCII.GetBytes(iv);
  11.             byte[] saltBytes = Encoding.ASCII.GetBytes(saltV);
  12.             byte[] textBytes = Encoding.UTF8.GetBytes(text);
  13.  
  14.             PasswordDeriveBytes key = new PasswordDeriveBytes(
  15.                 password, saltBytes, hashAlgorithm, passwordIterations);
  16.  
  17.             byte[] keyBytes = key.GetBytes(keySize / 8);
  18.  
  19.             RijndaelManaged symmetricKey = new RijndaelManaged();
  20.             symmetricKey.Mode = CipherMode.CBC;
  21.  
  22.             ICryptoTransform encryptor =symmetricKey.CreateEncryptorkeyBytes, ivBytes);
  23.  
  24.             MemoryStream memoryStream = new MemoryStream();
  25.             CryptoStream cryptoStream = new CryptoStream(memoryStream,  cryptor, CryptoStreamMode.Write);
  26.             cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
  27.             cryptoStream.FlushFinalBlock();
  28.  
  29.             byte[] cipherTextBytes = memoryStream.ToArray();
  30.             memoryStream.Close();
  31.             cryptoStream.Close();
  32.             return Convert.ToBase64String(cipherTextBytes);
  33.         }
************************************************** **********************************
PHP coding:
Expand|Select|Wrap|Line Numbers
  1. function decrypt($crytedText) {
  2. $key = "abc";
  3. $iv = "123456789123456";
  4. $text = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key,$cryptedText, MCRYPT_MODE_CBC, $iv);
  5. echo("<p>".$text);
  6. }
Feb 28 '09 #1
0 1227

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Todd Gruben | last post by:
I am trying to send some encrypted data from a php application to be decoded in a .Net application. Both apps encode/decode a given string but generate different encrypted results. Anyone have...
2
by: Leonardo D'Ippolito | last post by:
Hi! I have two .NET win apps that need to communicate on a TCP/IP network. 'App A' must ask 'app B' if it's allowed to do some task, and 'app B' must authorize or prohibit it. How can I do...
0
by: Li Pang | last post by:
Hi, My inbox receives regularly the encrypted emails. I made a small app by using outlook activeX to read the emails (decrypted by outlook). I just want to know if outlook application provides a...
1
by: Martin | last post by:
Is there a way to create and encrypted database file? What do people do when data security is important at the file level? In other words, you don't want anyone to be able to take the database...
0
by: VBTricks.de.vu Webmaster | last post by:
Hello, I'm trying to implement an encrypted communication with a PHP script. All the basic stuff (HTTP protocoll, base64) is working. The only problem is that this method works only for the...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
2
by: Bernard Dhooghe | last post by:
The information center writes: "Encryption Algorithm: The internal encryption algorithm used is RC2 block cipher with padding, the 128-bit secret key is derived from the password using a MD2...
1
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
2
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.