.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Encrypt in PHP, decrypt in ASP.NET - Encryption doesn't match

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :ASP.Net

Hello all,

I have a problem decrypting a string in ASP.NET wich was encrypted at PHP. As a testcase, i tried to encrypt 'test' in ASP.NET and in PHP, using 3DES in cbc mode. But the encrypted values don't match :(. I want the values to match, so i know for sure i use the same encryption method. Please help me on this, I just don't understand how there are different values...

Here's the code i use in php: 

$cc = "test";

$key = pack("c*", 0x13, 0x56, 0x23, 0x15, 0x81, 0x28, 0x56, 0x51, 0x13, 0x56, 0x23, 0x15, 0x81, 0x28, 0x56, 0x52, 0x13, 0x56, 0x23, 0x15, 0x81, 0x28, 0x56, 0x51);
$iv = pack("c*", 0x42, 0x32, 0x84, 0x25, 0x79, 0x43, 0x11, 0x37);

      $block = mcrypt_get_block_size('tripledes', 'cbc');
      $len = strlen($cc);
      $padding = $block - ($len % $block);
      $cc .= str_repeat(chr($padding),$padding);

$cipher = mcrypt_module_open(MCRYPT_3DES,'','cbc','');
mcrypt_generic_init($cipher, $key, $iv);
$encrypted = mcrypt_generic($cipher,$cc);
echo base64_en

View Complete Post

More Related Resource Links

Encrypt It: Keep Your Data Secure with the New Advanced Encryption Standard


The Advanced Encryption Standard (AES) is a National Institute of Standards and Technology specification for the encryption of electronic data. It is expected to become the accepted means of encrypting digital information, including financial, telecommunications, and government data. This article presents an overview of AES and explains the algorithms it uses. Included is a complete C# implementation and examples of encrypting .NET data. After reading this article you will be able to encrypt data using AES, test AES-based software, and use AES encryption in your systems.

James McCaffrey

MSDN Magazine November 2003

Is it possible to write the same encrypt and decrypt method that in MembershipProvider


Hi, I am very confused about encrypting and decrypting password.

What I did is that, I am using a class that extends SqlMembershipProvider, and when I need to encrypt a password, just called base.EncryptPassword() method to do so.

But still, I did not get to know how things are done here, and I really would like to know its codes.

Can anyone provide the code for me please?


How to encrypt and decrypt stored procedures?

I encrypt my procedures using with encryption clause, but I do not how to decrypt again.    Is there a command or utility for encrypt and decrypt in Sql 2000? How about Sql 2005? Thanks Haydee

SharePoint 2010 - The license state for the current server doesn't match the farm's license state.

I already have a SharePoint 2010 server built, up and running. Yesterday I built a brand new server Windows 2008 and installed all necessary windows updates. Then I joined the server to the domain where the other SharePoint 2010 box is. Today, I installed all necessary pre-requisites for SharePoint 2010 including the KB971831. After that I installed SharePoint 2010 binaries on the new server. When I run the configuration wizard now, it sees the database server with the configuration database, but will not allow me to join the new server to the farm. I get the following error in the diagnostic logs. Resource retrieved id ConfigurationDatabaseTaskConnectFailConfigDisplayLabel is Failed to connect to the configuration database. 02/18/2010 17:54:12 8 INF Leaving function StringResourceManager.GetResourceString 02/18/2010 17:54:12 8 ERR Failed to connect to the configuration database.   An exception of type System.InvalidOperationException was thrown. Additional exception information: The current server cannot be joined to this farm because the set of installed products does not match the products installed in the farm.   The license state for the current server doesn't match the farm's license state. System.InvalidOperationException: The current server cannot be joined to this farm because the set of installed products does not match the products installed in the farm.

The license state for the current server doesn't match the farm's license state.

Help!!!! I removed project server 2010 from my server hosting SP 2010 and when I run the config wizard I get the error The license state for the current server doesn't match the farm's license state.  I need to bring it back online asap... :(  Any ideas please.

encrypt and decrypt md5 hash text


i am encrypting textbox value in md5 using this coding and passing as querystring , and on other page i want to decrypt.....

so plz tell how can i do this..

System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] bs = System.Text.Encoding.UTF8.GetBytes(TextBox1.Text);
        bs = x.ComputeHash(bs);
        System.Text.StringBuilder s = new System.Text.StringBuilder();
        foreach (byte b in bs)
        string password = s.ToString();

RSA Encryption - Encrypt with private key

Hey everyone, 

I am looking for a way to encrypt data with a private key, and have the public key decrypt it. I am aware this is generally NOT what you want from encryption, as it will be readable with by anyone with the public key, but that is exactly what I require. 

I require a string of data to be encrypted by the private key, so that only I can create the encrypted data, and have my application read it by the public key. The idea behind this is to create a license file for my application, encrypt the license details, and have the application read this data. This will prevent licenses being generated by anyone other than me, however will allow the application to read it by the public key. 

The idea of this is to control the encrypted data, and not care who can read it, only who can create it. 

Using the RSACryptoServiceProvider, I can create my public/private keys, I can encrypt the data with the private key, however when I go to decrypt with the public key, I get a "Key Not Found" exception. 

Signing with RSA is also not possible, as I need to compare encrypted data with plain text data, to ensure the license is valid, and signing only verifies the source, not what it contains

AES - Encrypt message in Java / Decrypt in asp.net


im currently developing a project which requires to encrypt message in java platform and decrypt in asp.net. In java, i was asked to use the code below to encrypt the message. But i found out i could not decrypt it as i do not know how to get the key, IV fom java. By the way, im using AES decryption method from http://www.obviex.com/samples/Encryption.aspx.

   import java.security.*;
   import javax.crypto.*;
   import javax.crypto.spec.*;
   import java.io.*;

   * This program generates a AES key, retrieves its raw bytes, and
   * then reinstantiates a AES key from the key bytes.
   * The reinstantiated key is used to initialize a AES cipher for
   * encryption and decryption.

   public class AES {

     * Turns array of bytes into string
     * @param buf	Array of bytes to convert to hex string
     * @return	Generated hex string
     public static String asHex (byte buf[]) {
      StringBuffer strbuf = new StringBuffer(buf.length * 2);
      int i;

      for (i = 0; i < buf.length; i++) {
       if (((int) buf[i] & 0xff) < 0x10)

       strbuf.append(Long.toString((int) buf[i] & 0xff, 16));

      return strbuf.toString();

     public static void main(String[] args) throws Exception

Errors in the encryption library: Failed to encrypt sensitive data. Possibly the encryption key is i

Hi Experts,

While I was processing my CUBE, it prompts me this error:

Errors in the encryption library: Failed to encrypt sensitive data. Possibly the encryption key is inaccessible because of improper service account change.


it is deployed on SQL Server 2005 developer edition with SP2 which support Window Vista Ultimate.

Can anyone fix this?


How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

How to Encrypt and Decrypt a Password using SQLSERVER 2005?(Video)

Encypt and Decrypt a Password using SQLSERVER 2005(Video)

Beginner: this doesn't make sense to me


Do you need and "empty" script tag in the head to run scripts that are in the body?  Also, can you run JQuery scripts if they're in the <head> tag?  The first sample only works if the JQuery script is in the form (and body) tag, not in the head - even if I add $(document).ready(function() { });

This works

<head runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />
<script type="text/javascript">
<form id="form1" runat="server">
<a href="">Here is a link</a>
<script type="text/javascript">
$('a').click(function () {
alert("you clicked me!");


This doesn't work.  Notice I removed the second <script> tag from the head

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="serve

The number of members in the conceptual type ... does not match with the number of members on the ob



I've added a scalar property to an entity and now ASP.NET Dynamic Data scaffolding throws this error:

The number of members in the conceptual type 'TrainingModel.Users' does not match with the number of members on the object side type 'TrainingModel.Users'. Make sure the number of members are the same.

This happens at the following line in global.asax:
model.RegisterContext(typeof(TrainingModel.TrainingEntities), new ContextConfiguration() { ScaffoldAllTables = true });

Please help!

View State Encryption


Hi All,

Why is it that I see the same hash value generated when I use different algorithms for viewstate encryption. I have added below lines to the web.config file

<pages viewstateEncryptionMode="Always"

{ End Bracket }: Legal Doesn't Think the Way You Do


If you develop software for a large company, you've undoubtedly experienced the joys of dealing with "Legal. " The meetings, the endless explanations, the long waits. I'm here to report from the other side.

Don McGowan

MSDN Magazine March 2006

Advanced Basics: A Match-Making Game in Visual Basic


My four-year-old son has decided that he wants to be like his dad when he grows up. He is planning to work in my office, and write computer programs just like I do. But there is one problem-he thinks I write games.

Duncan Mackenzie

MSDN Magazine October 2005

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend