Magento 2 – Using Vendor Library in Custom Module’s Helper File

magento-2.1

How can I use below vendor library in my custom module's helper file?
I want to create an object of this class.

/magento2/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php

I have tried with below in my helper file but not working.

use phpseclib\phpseclib\phpseclib\Crypt\RSA;

Also I tried to add using composer but still its not working.

{
"name": "company/module",
"description": "N/A",
"require": {
    "php": "~5.6.0|7.0.2|~7.0.6",
    "magento/magento-composer-installer": "*",
    "phpseclib/phpseclib":"*"
},
"type": "magento2-module",
"version": "2.0.0",
"license": [
    "proprietary"
],
"autoload": {
    "files": [
        "registration.php"
    ],
    "psr-4": {
        "Company\\Module\\": ""
    }
}

}

Best Answer

Try following way:

use \phpseclib\Crypt\RSA;

How to use:

$rsa = new RSA();
echo '<pre>';print_r($rsa->createKey(1024));
Related Topic