Pranav
Pranav

Reputation: 143

Alternative to mcrypt_encrypt?

As per the php 7.0 mcrypt_decrypt is deprecated.

I have following code.

$intSize= mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
$strSize = mcrypt_create_iv( $intSize, MCRYPT_RAND );
$strText = ( true == $boolTrimText ) ? trim( $strText ) : $strText;
$strResult = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, ( string ) $strKey, ( string ) $strText, MCRYPT_MODE_ECB, $strSize) );

Now we are getting

mcrypt_encrypt(): Key of size 0 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported

Any alternative to fix this warning?

Upvotes: 2

Views: 16327

Answers (3)

Sumon Sarker
Sumon Sarker

Reputation: 2795

Use String length 16 or 24 or 32 for variable $strKey

$strKey = 'YOUR_STRING'; #This string length should be 16 or 24 or 32

Example :

$strKey = '1234567890abcdef';                 #Length 16
$strKey = '1234567890abcdef76hgfrdg';         #Length 24
$strKey = '1234567890abcdef1234567890abcdef'; #Length 32

Here is the details about mcrypt_encrypt()

Alternate Solutions :

Upvotes: 1

JAVA_RMI
JAVA_RMI

Reputation: 139

If you want to go encryption/decryption have a look upon this blog post
https://paragonie.com/white-paper/2015-secure-php-data-encryption it will tell you how to do it in proper way.

Alternative http://php.net/manual/en/intro.openssl.php This extension binds functions of » OpenSSL library for symmetric and asymmetric encryption and decryption.

Upvotes: 2

Farhad Hossen
Farhad Hossen

Reputation: 273

You should use openssl_encrypt. here the link : http://php.net/manual/en/function.openssl-encrypt.php

Upvotes: 4

Related Questions