Quick actions

cmd+k|ctrl+k

Navigation

Languages

Encryption/decryption with special key in PHP

Snippet info

Language

Php

Visibility

public

Author

mertskaplan

Created

2016-12-22T11:30:37Z

Updated

2016-12-28T22:47:42Z

<?php

function encryption($dataToEncrypt, $secretHash = 'dataKey', $iv = '1234567812345678') {
	$encryptionMethod = 'AES-256-CBC';
	$secretHash = md5($secretHash);
	$encryptedData = openssl_encrypt($dataToEncrypt, $encryptionMethod, $secretHash, false, $iv);
	return $encryptedData;
}

function decryption($dataToDecrypt, $secretHash = 'dataKey', $iv = '1234567812345678') {
	$decryptionMethod = 'AES-256-CBC';
	$secretHash = md5($secretHash);
	$decryptedData = openssl_decrypt($dataToDecrypt, $decryptionMethod, $secretHash, false, $iv);
	return $decryptedData;
}

/*	Using
	encryption('kamil', 'comolokko', 'dfg76df87g6d8f7g'); or encryption('kamil');
	decryption($deneme, 'comolokko', 'dfg76df87g6d8f7g'); or decryption($deneme);
*/

echo encryption('kamil') . "\n";
echo decryption(encryption('kamil'));
INFO