Commit a2d1ee33 authored by Radek Suski's avatar Radek Suski

Encryption: failsafe for not yet encrypted data

parent c2732496
......@@ -35,9 +35,14 @@ class Encryption
return base64_encode( json_encode( $r ) );
}
public static function Decrypt( $data, $key )
public static function Decrypt( $input, $key )
{
$data = json_decode( base64_decode( $data ), true );
return openssl_decrypt( base64_decode( $data[ 'data' ] ), $data[ 'cipher' ], $key, $options = 0, base64_decode( $data[ 'iv' ] ), base64_decode( $data[ 'tag' ] ) );
$data = json_decode( base64_decode( $input ), true );
if ( is_array( $data ) && isset( $data[ 'cipher' ] ) ) {
return openssl_decrypt( base64_decode( $data[ 'data' ] ), $data[ 'cipher' ], $key, $options = 0, base64_decode( $data[ 'iv' ] ), base64_decode( $data[ 'tag' ] ) );
}
else {
return $input;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment