473,785 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encrypted in C# and decrypted in PHP

1 New Member
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 1241

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

Similar topics

3
4475
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 any idea? Code to follow: php====> <?php // Designate string to be encrypted $string = "This is a test";
2
5139
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 this kind of communication in a secure way (protected from sniffing)? It would be a very simple protocol. Question, and two possible answers 'yes' or 'no'.
0
1015
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 method to tell me that an email was encrypted, or it was decrypted from an encrypted one, some thing like IsEncrypted or similar. Anyone can give me a help? Thank in advance
1
1733
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 file (or files) and extract data from them. Ideally, I want a file the is absolutely encrypted on disk and that is decrypted for data access. The problem, obviously, is that this would be a very costly (cpu time) approach as you couldn't create...
0
1330
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 first 8 letters of the encrypted string, the rest seems to be not decrypted. I guess, it's the IV-vector. Unfortunately, I have no experience with encryption:
5
6777
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 cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
2
7694
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 message digest. " and also explains how the length of the encrypted column can be derived.
1
4836
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 algorithm, initialization vector (IV), mode, padding, key etc, but I just don't get the two languages to "understand each other", or, in other words, I must be missing out on something crucial. I encrypt a byte array in C# and send over the byte...
2
17969
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 algorithm, initialization vector (IV), mode, padding, key etc, but I just don't get the two languages to "understand each other", or, in other words, I must be missing out on something crucial. I encrypt a byte array in C# and send over the byte...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.