Use ICrypto in class

I try to use the method encrypt() of ICrypto to store a password after logging users in.

My problem is not really a nextcloud but a PHP thing but this problem belongs to nextcloud.
How can I use the method?!
My class uses this:

use \OC_DB;
use OCP\Security\ICrypto;
abstract class Base extends \OC_User_Backend {
	protected $backend = '';
	public function __construct($backend) {
		$this->backend = $backend;
	}
}

I searched within this repo and within apps but the only thing I found was

public function __construct($backend, ICrypto $crypto) {
    $this->backend = $backend;
    $this->crypto = $crypto;
}

I’m really consfused and appreciate any hints - many thanks in advance!

You do want to use Dependency Injection to inject ICrypto. The following in app.php will inject the required classes into your user backend class. You can get the ICrypto object with \OC::$server->getCrypto()

Then in the constructor take the arguments, assign it to a local member variable and use it later with $this->crypto->encrypt():

This first part was helpful because I could use this “out of the box” within the class. The structure of my app is different to yours (I took this from user_external) so I’m gonna change this from scratch to improve it.

Thank you!