This topic is locked

Encryption/Decryption

11/28/2025 15:38:28
PHPRunner General questions
S
Simtrain author

I have a table that contains a field that I have encrypted. When I run PHPRunner, it shows OK in my tables on my website, and shows as being encrypted in the sql database..

My problem is I want to be able to call that table (field) into my mobile app, but I have spent all day trying to get it to work, to no avail!

I would prefer to have the decrypt in a dart file, but PHP would be a good second choice.

I have tried AES 128 amongst others, and nothing seems to work.

Can anyone point me in the right direction?

Many thanks in advance

Steve

ChatGPT 11/28/2025

Hi Steve,

It sounds like you're dealing with encrypted data in your database and you want to access that data in your mobile app using Dart, or alternatively, using PHP. Here are some steps and tips that might help you to achieve this:

Step 1: Understand the Encryption Method

First, ensure you understand how the data is being encrypted in PHPRunner. If it's using AES (which is common), you'll need to know the encryption method (e.g., AES-128, AES-256), the mode of operation (e.g., CBC, ECB), and the key used for encryption. Make sure you have the same key available for decryption.

Step 2: Decrypting in PHP

If you're open to using PHP, you can use the openssl_decrypt function. Here's a basic example of how you might decrypt data in PHP:

function decryptData($encryptedData, $encryptionKey) {
// Assuming you are using AES-128-CBC
$iv = 'YOUR_INITIALIZATION_VECTOR'; // Make sure to use the same IV that was used for encryption
$decryptedData = openssl_decrypt(base64_decode($encryptedData), 'AES-128-CBC', $encryptionKey, OPENSSL_RAW_DATA, $iv);
return $decryptedData;
}

// Usage
$encryptedData = 'YOUR_ENCRYPTED_DATA';
$encryptionKey = 'YOUR_ENCRYPTION_KEY';
$decryptedData = decryptData($encryptedData, $encryptionKey);
echo $decryptedData;

Step 3: Decrypting in Dart

If you prefer to do it in Dart, you can use the encrypt package, which supports AES encryption and decryption. Here’s a basic example:

  1. Add the dependency to your pubspec.yaml:

dependencies:
encrypt: ^5.0.0
  1. Use the encrypt package to decrypt the data:

import 'dart:convert';
import 'package:encrypt/encrypt.dart';
import 'package:encrypt/encrypt.dart' as encrypt;

String decryptData(String encryptedData, String key, String iv) {
final keyBytes = Key.fromBase64(key);
final ivBytes = IV.fromBase64(iv);

final encrypter = Encrypter(AES(keyBytes));

final decrypted = encrypter.decrypt64(encryptedData, iv: ivBytes);
return decrypted;
}

// Usage
void main() {
String encryptedData = 'YOUR_ENCRYPTED_DATA';
String encryptionKey = 'YOUR_ENCRYPTION_KEY'; // Should be base64 encoded
String initializationVector = 'YOUR_INITIALIZATION_VECTOR'; // Should be base64 encoded

String decryptedData = decryptData(encryptedData, encryptionKey, initializationVector);
print(decryptedData);
}

Step 4: Test and Debug

  • Make sure that the key and IV used in both PHP and Dart match what was used during encryption.
  • Ensure that the encrypted data is correctly passed to the decryption function (e.g., check for any encoding issues).
  • Test with known values to ensure that your decryption logic is correct.

Step 5: Secure Your Keys

Remember to keep your encryption keys and initialization vectors secure. Avoid hardcoding them directly in your source code, and consider using environment variables or secure storage mechanisms.

Conclusion

By following these steps, you should be able to decrypt your encrypted data either in PHP or Dart. If you encounter specific errors or issues, feel free to provide more details, and I can assist you further. Good luck!

Sergey Kornilov admin 11/28/2025

The article in the manual that explains encryption/descryption also shows an example of manual data decryption:
https://xlinesoft.com/phprunner/docs/encryption.htm#decrypt

Another option, expesially since you plan to use a mobile application, you can use PHPRunner's REST API to retrieve data and it will descrypt it for you automatically.