How to encrypt and decrypt string in Magento 2?

You can Encrypt or Decrypt any string using Magento 2 with native interface functionality.

You can encrypt or decrypt password or credit card data or any value you need to encrypt using Magento\Framework\Encryption\EncryptorInterface interface.

Example, You can encrypt the password with below way,

You need to call for encrypt,


and Decrypt,