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);
?>
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class OpenSSLExample {
public static void main(String[] args) throws Exception {
String body = "your_body";
String method = "AES/CBC/PKCS5Padding";
String ciphertext = "your_ciphertext";
String API_key = "your_api_key";
SecretKeySpec keySpec = new SecretKeySpec((ciphertext + API_key).getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance(method);
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
byte[] encryptedBytes = cipher.doFinal(body.getBytes(StandardCharsets.UTF_8));
String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes);
System.out.println(encryptedText);
}
}
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import base64
body = b'your_body'
method = 'AES/CBC/PKCS5Padding'
ciphertext = 'your_ciphertext'
API_key = 'your_api_key'
key = (ciphertext + API_key).encode('utf-8')
cipher = AES.new(key, AES.MODE_CBC)
# Padding the data to match the block size
padded_data = pad(body, AES.block_size)
encrypted_bytes = cipher.encrypt(padded_data)
encrypted_text = base64.b64encode(encrypted_bytes).decode('utf-8')
print(encrypted_text)
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;
?>
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class OpenSSLDecryptionExample {
public static void main(String[] args) throws Exception {
String encryptedText = "your_encrypted_text";
String method = "AES/CBC/PKCS5Padding";
String ciphertext = "your_ciphertext";
String API_key = "your_api_key";
SecretKeySpec keySpec = new SecretKeySpec((ciphertext + API_key).getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance(method);
cipher.init(Cipher.DECRYPT_MODE, keySpec);
byte[] encryptedBytes = Base64.getDecoder().decode(encryptedText);
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
String decryptedText = new String(decryptedBytes, StandardCharsets.UTF_8);
System.out.println(decryptedText);
}
}
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import base64
encrypted_text = 'your_encrypted_text'
method = 'AES/CBC/PKCS5Padding'
ciphertext = 'your_ciphertext'
API_key = 'your_api_key'
key = (ciphertext + API_key).encode('utf-8')
cipher = AES.new(key, AES.MODE_CBC)
# Decoding base64 and decrypting the text
encrypted_bytes = base64.b64decode(encrypted_text)
decrypted_bytes = unpad(cipher.decrypt(encrypted_bytes), AES.block_size)
decrypted_text = decrypted_bytes.decode('utf-8')
print(decrypted_text)
Last updated