php encryption thats unencryptable in delphi

Posted on 2005-05-04
Last Modified: 2010-04-04
I think the question title says it all.   I need to encrypt something in PHP that can be unencrypted in delphi.  Any ideas?

Question by:hibbidiji
    LVL 15

    Expert Comment

    What are you trying to encrypt in PHP?
    As long as you stick to the same encryption method within both PHP and Delphi I wouldnt have thought there would be an issue.
    LVL 13

    Expert Comment

    as mikelittlewood says, if you provide the method you are using to encrypt in PHP, some one can come up with an algorithm to decrypt or point out some resources of already built solutions for such algorithm
    LVL 26

    Expert Comment

    He must be talking about the PHP crypt function.

    crypt -- One-way string encryption (hashing)

    crypt() will return an encrypted string using the standard Unix DES-based
    encryption algorithm or alternative algorithms that may be available on the system.

    No way to decrypt it, however. It is a one-way hash like MD5.
    LVL 26

    Expert Comment

    I think the OP needs to further define his requirements.
    LVL 1

    Author Comment

    Pardon me folks.   I will write a code example of how i USUALLY encrypt in php.

    $data = $datatemp;
    $key = "keyhere";
    $td = MCRYPT_RIJNDAEL_256;

    $encrypted_data = @mcrypt_encrypt($td, $key, $data, MCRYPT_MODE_CBC);

    This has its disadvantages.   Here is my application:

    Delphi 2005 applicaiton  reads encrypted database from web server and writes an encrypted temp file to disc.   App decrypts it at runtime in memory, leaving the temp file encrypted for mild security.   (I know that people can do memory dumps and get my db, its not THAT important, just mild encryption or obfuscation is needed)

    The downsides with my above example are that it requires either mcrypt or similar bloat to the delphi app, and that it generates a binary file that is not as easily transferred with http over the net.   I can happily zip the file for transfer (I have a zip componenet for delphi) or use FTP if you folks think my existing idea is best.   Just looking for options.  Thanks!

    LVL 1

    Author Comment

    Further clarification:

    Database is > 500k & <20mb

    LVL 26

    Accepted Solution

    in the PHP code above, $encrypted_data is a STRING.

    Here is docs on the mcrypt_encrypt PHP function:

    mcrypt_encrypt -- Encrypts plaintext with given parameters

    string mcrypt_encrypt ( string cipher, string key, string data, string mode [, string iv] )

    mcrypt_encrypt() encrypts the data and returns the encrypted data.

    Cipher is one of the MCRYPT_ciphername constants of the name of the algorithm as string.
    {DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2,
     GOST in CBC, OFB, CFB and ECB; see for the
    string constants to use}

    Key is the key with which the data will be encrypted. If it's smaller that the required keysize,
    it is padded with '\0'. It is better not to use ASCII strings for keys. It is recommended to use
    the mhash functions to create a key from a string.

    Data is the data that will be encrypted with the given cipher and mode. If the size of the data
    is not n * blocksize, the data will be padded with '\0'. The returned crypttext can be larger
    that the size of the data that is given by data.

    Mode is one of the MCRYPT_MODE_modename constants of one of "ecb", "cbc", "cfb", "ofb",
    "nofb" or "stream".

    The IV parameter is used for the initialisation in CBC, CFB, OFB modes, and in some algorithms
    in STREAM mode. If you do not supply an IV, while it is needed for an algorithm, the function
    issues a warning and uses an IV with all bytes set to '\0'.

    You can use PHP to do this from your Delphi application using PHP4Delphi. However, you must have
    libmcrypt installed also. Look at the accepted answer here:

    LVL 1

    Author Comment

    I've contacted the author of dcpcrypt and have a solution.

    LVL 26

    Expert Comment

    Could you post the solution here for everyone?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now