Skip to content

Instantly share code, notes, and snippets.

@tronsha
Last active January 8, 2016 12:40
Show Gist options
  • Save tronsha/dc09f316af4197c2fc9c to your computer and use it in GitHub Desktop.
Save tronsha/dc09f316af4197c2fc9c to your computer and use it in GitHub Desktop.
Mircryption
<?php
function mircryption_decode($text, $key)
{
$encodedTextIvBase64 = str_replace('*', '', $text);
$encodedTextIv = base64_decode($encodedTextIvBase64);
$iv = substr($encodedTextIv, 0, 8);
$encodedText = substr($encodedTextIv, 8);
$plaintext = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $encodedText, MCRYPT_MODE_CBC, $iv);
return trim($plaintext);
}
function mircryption_encode($text, $key)
{
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC), MCRYPT_RAND);
$encodedText = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $text, MCRYPT_MODE_CBC, $iv);
$encodedTextIv = $iv . $encodedText;
$decodedTextBaseIv64 = base64_encode($encodedTextIv);
return '*' . $decodedTextBaseIv64;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment