WebFaction
Community site: login faq

On a PHP 5.5 site I have this :

# http://stackoverflow.com/questions/16600708/how-do-you-encrypt-and-decrypt-a-php-string

/**
 * Returns an encrypted & utf8-encoded
 */
function encrypt($pure_string, $encryption_key) {
    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
    return $encrypted_string;
}

/**
 * Returns decrypted original string
 */
function decrypt($encrypted_string, $encryption_key) {
    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, $encrypted_string, MCRYPT_MODE_ECB, $iv);
    return $decrypted_string;
}

# http://richardpeacock.com/blog/2011/08/encode-any-string-only-alphanumeric-chars-better-urlencode
function hex_encode($input) {
  return bin2hex($input);
}

function hex_decode($input) {
  return pack("H*", $input);
}

I want to change my app from 5.5 to 7.2. How can I replace the first 2 functions ?

asked 07 Apr, 10:04

anjanesh
66619
accept rate: 25%


All mcrypt_* functions have been removed from PHP 7.2 so this code will not work indeed. You should use openssl functions instead. See the related official wiki article here.

You are using mcrypt_get_iv_size, mcrypt_create_iv, mcrypt_encrypt and mcrypt_decrypt.

I believe the relevant functions now are openssl_cipher_iv_length, random_bytes, openssl_encrypt and openssl_decrypt.

All the openssl functions can be found here.

permanent link

answered 07 Apr, 14:26

iliasr ♦♦
1.9k14
accept rate: 36%

edited 07 Apr, 14:54

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×1

question asked: 07 Apr, 10:04

question was seen: 295 times

last updated: 07 Apr, 14:54

Related questions

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM