How to encrypt and decrypt data

Encryption

API Encryption

All of the body data will need to be encrypted using AES-256. The response also will be in encrypted AES-256

Detail:

● Encryption Method: openssl_encrypt AES-256

● body: request body

● Method: aes-256-cbc

● Ciphertext: Provided by Innov8tif

● API_key: Provided by Innov8tif

Encryption Formula:

data = openssl_encrypt(body, method, ciphertext+API_key, OPENSSL_RAW_DATA, ciphertext)


$body = 'your_body';
$method = 'AES-256-CBC';
$ciphertext = 'your_ciphertext';
$API_key = 'your_api_key';

$key = $ciphertext . $API_key;

$encryptedText = openssl_encrypt($body, $method, $key, OPENSSL_RAW_DATA, $ciphertext);

echo base64_encode($encryptedText);
?>

Decryption

<?php

$encryptedText = 'your_encrypted_text';
$method = 'AES-256-CBC';
$ciphertext = 'your_ciphertext';
$API_key = 'your_api_key';

$key = $ciphertext . $API_key;

$decryptedText = openssl_decrypt(base64_decode($encryptedText), $method, $key, OPENSSL_RAW_DATA, $ciphertext);

echo $decryptedText;
?>

Last updated