Home 
username password  
Welcome, Guest.
Your IP: 100.28.231.85
2024-11-04 23:26:19 
 Public Support
 How to decrypt text that has been encrypted with PHP
Bottom
 
Total posts: 3
 Author How to decrypt text that has been encrypted with PHP
Rael Bauer

2018-04-30 15:56:28
Registered user
Hi,

I am trying to achieve some "lightweight" encryption in PHP and decryption in Delphi.

I found this entry on Stack Overflow on how to encrypt a string in PHP:

https://stackoverflow.com/questions/1788150/how-do-i-encrypt-a-string-in-php

and would like to use this method: (since it works with older versions of PHP)

<?php

$methods = openssl_get_cipher_methods();

echo $methods.count . " methods <br>";

$counter = 0;
foreach ($methods as $method){
  echo $counter. ". " . $method . "<br>";
  $counter++;
}

$textToEncrypt = "he who doesn't do anything, doesn't go wrong -- Zeev Suraski";
$secretKey = "glop";

echo '<pre>';
foreach ($methods as $method) {
    $encrypted = openssl_encrypt($textToEncrypt, $method, $secretKey);
    $decrypted = openssl_decrypt($encrypted, $method, $secretKey);
    echo $method . ': ' . $encrypted . ' ; ' . $decrypted . "\n";
}
echo '</pre>';

Here is some sample output:

AES-128-CBC: wELezn3CCuPyuCJ0x7S3H5fpS21W2k0dcuAnMeY/VwgdrhX5H5NI7tI4hn+FlTuy9MfrLGUXe+OjmQlxnH7SNA== ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski

BF-CBC: /nyRYCzQPE3ZiLjw1vs/duqEk+fySyMNuxSjwtBbCYMv2sngQLoardQkQqK+jMzqYggu1YG9G9Tuw46xFmnbIA== ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski

Can you help with how to decrypt this in Delphi?

Using ST_2.3.1.273, DXE4

Thank you
Rael
Henrick Wibell Hellström

2018-04-30 17:57:55
Registered user
The AES-128-CBC decryption code is below:


uses
  SecUtils, SsRijndael, SsBase64;
...
const
  CipherText = 'wELezn3CCuPyuCJ0x7S3H5fpS21W2k0dcuAnMeY/VwgdrhX5H5NI7tI4hn+FlTuy9MfrLGUXe+OjmQlxnH7SNA==';
  Password = 'glop'#0#0#0#0#0#0#0#0#0#0#0#0;
var
  S: OctetString;
begin
  S := MIME64ToStr(CipherText);
  S := DecryptString(caRijndael,cmCBC,Password,S);
  ShowMessage(S);
Rael Bauer

2018-04-30 18:59:57
Registered user
Thanks alot.
Top

:: Written with and Powered by the RealThinClient SDK and StreamSec Tools 4.0::
Copyright (c) Danijel Tkalcec, StreamSec HB