-2

need help to convert the following function in php. Can any one help me please ?

OpenEdge Progress 4 GL

DEFINE VARIABLE cClearText      AS CHARACTER NO-UNDO.
DEFINE VARIABLE rBinaryKey      AS RAW       NO-UNDO.
DEFINE VARIABLE rEncryptedValue AS RAW       NO-UNDO.
DEFINE VARIABLE cEncryptedText  AS CHARACTER NO-UNDO.

ASSIGN
    cClearText = "This is the clear text string to be encrypted."

    rBinaryKey = GENERATE-PBE-KEY("password")

    SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_OFB_128"
    SECURITY-POLICY:SYMMETRIC-ENCRYPTION-KEY = rBinaryKey
    SECURITY-POLICY:SYMMETRIC-ENCRYPTION-IV = ?
    rEncryptedValue = Encrypt (cClearText)
    cEncryptedText = BASE64-ENCODE(rEncryptedValue)
    .
MESSAGE "Encrypted Message:" cEncryptedText
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

in php

$key = "password"; 
$text =  "This is the clear text string to be encrypted."; 
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); 
/*$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); */
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv); 
echo $crypttext;

but not the same result???

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
  • 1
    Questions asking for code need to show an attempt and offer an explanation as to what problem you've run into. Would you edit your question? I'll vote to unhold if you can do so. – halfer Oct 04 '13 at 16:06

2 Answers2

4

Is it just my imagination or are you using AES_OFB_128 as the algorithm with the OpenEdge code and RIJNDAEL_256 for the PHP code?

It seems to me that you should get a different result.

Shouldn't you have the same mode and key size? (IOW AES_ECB_256 instead of AES_OFB_128 in the OpenEdge code.)

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
0

changed to SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_CBC_128".

In php:

$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC); 

The problem is that Converting the passphrase into a password based encryption key (PBE-KEY) through Progress is not returning the same values as in php.

4gl:

rawBinaryKey = GENERATE-PBE-KEY("pw").

Not returning the same on php:

$key = "pw"; 

I need to know how to execute through php a function returning the same value as "GENERATE-PBE-KEY("pw")" is returning on Progress 4GL.

Kind regards

  • 2
    The docs (you have read the docs?) say that GENERATE-PBE-KEY "Generates a password-based encryption key, based on the PKCS#5/RFC 2898 standard, and returns the key as a RAW value." -- quickly searching Google for "php rfc 2898" returns: http://php.net/manual/en/function.hash-hmac.php – Tom Bascom Oct 10 '13 at 19:23