Home Forums ActiveX components Xceed Encryption for ActiveX Decrypt data from PHP Mcrypt

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #42937 |

    I would like to encrypt some user data from PHP on Linux, and then bring the data to a windows terminal and decrypt it. Of cource both muchine using same encryption method, key size and so on. I have made a simple PHP code and decode from the demo program (VB6). But the result is fail, the decrypt string is unreadable event i try all the options in the demo program.

    Does any one have this kind of experiance or tell me what is my wrong ?

    Thank you for your reading.

    Danny Ho

    PHP Code :
    ——————————————————–
    $key = “pass_key”;
    $data = “0123456789ABCDEFGHIJKLMNOPQRSTUV”;

    $CryptMethod = MCRYPT_RIJNDAEL_128;
    $CryptMode = MCRYPT_MODE_ECB;
    $CryptPaddingMode = MCRYPT_RAND;

    $iv_size = mcrypt_get_iv_size($CryptMethod, $CryptMode);
    $iv = mcrypt_create_iv($iv_size, $CryptPaddingMode);come together with Xc
    $crypttext = mcrypt_encrypt($CryptMethod, $key, $src, $CryptMode, $iv);
    echo “Encrypted data : (“.strlen(asciihex2hex($crypttext)).”) – “.strtoupper(asciihex2hex($crypttext)).”<br>\n”;

    function asciihex2hex( $str ) {
    $hexStr = ”;
    for ( $i=0,$j=strlen($str); $i<$j; $i++ ) {
    $hex = bin2hex($str[$i]);
    $hexStr .= strlen($hex)==1 ? ‘0’.$hex : $hex;
    }
    return $hexStr;
    }

    VB6 Code :
    ——————————————————–
    Using the example program “Xceed Encryption Library 1.1” come from the “Xceen Component”.

    Imported from legacy forums. Posted by dannyho (had 10533 views)

    User (Old forums)
    Member
    Post count: 23064

    I was forget to supply the following informations.

    the version of PHP is 4.4.0-4 on debian linux
    the name of VB6 test program is “MemoryEncrypt”

    Imported from legacy forums. Posted by dannyho (had 723 views)

    User (Old forums)
    Member
    Post count: 23064

    We have never tested our control in PHP nor is it something that we support. That being said, I would still be interested to see if anyone has been successful in the process.

    Edit : My apologies, I think I might have miss understood. Can you tell me which algorithm you use exactly along with the initialization vector hashing method etc… please provide me with more details about the encrypted data in question.

    Imported from legacy forums. Posted by Matt (had 594 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry, i am a newbian of Encryption. So i don’t what is the step to debug the code
    in order to find out what is the problem. Can you give me an idea on how to solve
    my problem. The following is the details of my testing.

    The encryption is method is RIJNDAEL, 128 bit, ECB mode and random padding.
    Using linux version Mcrypt (5.1.2-1) module for PHP 4.

    Here is the result of the above PHP code (not post again).

    Encrypt KEY : pass_key
    Source DATA : 0123456789ABCDEFGHIJKLMNOPQRSTUV
    Encrypted string : 26769817F2575C6DC337F8D3ED784B4E2DDCC476C561639BCB45F180FA247008

    —-
    The decryption is using the demo program ‘MemoryEncrypt’ and no changes of the code.

    Here is the decryption setting :
    – Symmetric encryption mode
    – Pass phrase ‘pass_key’
    – Option :
    -> Encryption Method = Rijndael (AES)
    -> Encryption Mode = Free blocks (ECB)
    -> Key size = 128
    -> Hashing method = SHA
    -> Padding method = Random

    —-
    I have copy the encrypted string ‘267698…..47008’ into the right Encrypted text box and
    press the ‘Decrypt’ button. The result string in Decrypted text box is unreadable, seems
    a binary data.

    I have read the decrypt program but don’t know what the problem. Is it the unicode code
    problem in ‘MemoryEncrypt’ program ? or the Encryption method is different between Mcrypt
    and Xceed ?

    Basically, i need to encrypt my membership data from PHP and decrypt on VB6. It’s doesn’t
    matter on how and what encryption method is used. My concern is minimize the byte of encrypted
    data and the security.

    Imported from legacy forums. Posted by dannyho (had 768 views)

    User (Old forums)
    Member
    Post count: 23064

    Unix does not interpret bytes in the same way than a Win platform, this could be the cause of your issue. Can you send me a working example in php with the vb6 code (properties you set exactly) to support @ xceedsoft.com?

    I would like to investigate this matter further.

    Imported from legacy forums. Posted by Matt (had 525 views)

    User (Old forums)
    Member
    Post count: 23064

    I have try the following, but no successful decode in your demo program. The encrypted number of byte is different to PHP encrypted.

    PHP Code:
    —————
    $str = “This is my Data.”;
    //$key = “0123456789ABCDEF”; // Plain Text
    $key = sha1(“0123456789ABCDEF”); // SHA1 Hash Key
    echo bin2hex(encrypt_aes_cbc_128($str,$key));

    function encrypt_aes_cbc_128( $srcData, $key ) {
    // Encode in AES(Rijndael) 128bit, CBC mode

    // Key Padding
    // 128bit = 16 bytes (16 * 8 = 128)
    if ( strlen($key) < 16 ) { $iv_key = str_pad($key,16); }
    else { $iv_key = substr($key, 0, 16); }

    return mcrypt_cbc( MCRYPT_RIJNDAEL_128, $iv_key, $srcData, MCRYPT_ENCRYPT, $iv_key );
    }

    VB6 Code (Use your MemoryEncrypt as blueprint, and do little modofication):
    ‘ Set the Option to AES, CBC Mode, 128 bit, SHA, Random
    —————-
    ‘ A new button to init. key, data string and call the orginal button ‘cmdEncrypt_Click’
    Private Sub Command1_Click()
    txtPassPhrase.Text = “0123456789ABCDEF”
    txtDecryptedText.Text = “This is my Data.”

    cmdEncrypt_Click
    End Sub

    ‘ On function ‘PrepareEncryptionMethod’, modifier the following line.
    ‘ Call xRijndael.SetSecretKeyFromPassPhrase(txtPassPhrase.Text, m_lSecretKeySize)
    ‘ Change to
    Dim PassPhrase As Variant
    PassPhrase = StrConv(txtPassPhrase.Text, vbFromUnicode)
    Call xRijndael.SetSecretKeyFromPassPhrase(PassPhrase, m_lSecretKeySize)

    Imported from legacy forums. Posted by dannyho (had 10935 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.