diff --git a/composer.json b/composer.json
index 7cca6e5..2850fb1 100644
--- a/composer.json
+++ b/composer.json
@@ -5,6 +5,6 @@
   "license": "GPL-2.0+",
   "homepage": "https://www.drupal.org/project/real_aes",
   "require": {
-    "defuse/php-encryption": "dev-master"
+    "defuse/php-encryption": "^2.0"
   }
 }
diff --git a/src/Plugin/EncryptionMethod/RealAESEncryptionMethod.php b/src/Plugin/EncryptionMethod/RealAESEncryptionMethod.php
index bfb1800..46d6456 100644
--- a/src/Plugin/EncryptionMethod/RealAESEncryptionMethod.php
+++ b/src/Plugin/EncryptionMethod/RealAESEncryptionMethod.php
@@ -11,6 +11,8 @@ use Drupal\encrypt\EncryptionMethodInterface;
 use Drupal\encrypt\Plugin\EncryptionMethod\EncryptionMethodBase;
 use \Defuse\Crypto\Crypto;
 use \Defuse\Crypto\Exception as Ex;
+use \Defuse\Crypto\Key;
+use \Defuse\Crypto\Encoding;
 
 /**
  * Class RealAESEncryptionMethod.
@@ -34,9 +36,9 @@ class RealAESEncryptionMethod extends EncryptionMethodBase implements Encryption
       $errors[] = t('Defuse PHP Encryption library is not correctly installed.');
     }
 
-    // Check if we have a 128 bit key.
-    if (strlen($key) != 16) {
-      $errors[] = t('This encryption method requires a 128 bit key.');
+    // Check if the key size meets the requirement.
+    if (strlen($key) != Key::KEY_BYTE_SIZE) {
+      $errors[] = t("This encryption method requires a @size byte key.", array(‘@size' => Key::KEY_BYTE_SIZE));
     }
 
     return $errors;
@@ -47,11 +49,12 @@ class RealAESEncryptionMethod extends EncryptionMethodBase implements Encryption
    */
   public function encrypt($text, $key, $options = array()) {
     try {
+      // Defuse PHP-Encryption requires a key object instead of a string.
+      $key = Encoding::saveBytesToChecksummedAsciiSafeString(Key::KEY_CURRENT_VERSION, $key);
+      $key = Key::loadFromAsciiSafeString($key);
       return Crypto::encrypt($text, $key);
     }
-    catch (Ex\CryptoTestFailed $ex) {
-      return FALSE;
-    } catch (Ex\CannotPerformOperation $ex) {
+    catch (Ex\CryptoException $ex) {
       return FALSE;
     }
   }
@@ -61,12 +64,12 @@ class RealAESEncryptionMethod extends EncryptionMethodBase implements Encryption
    */
   public function decrypt($text, $key, $options = array()) {
     try {
+      // Defuse PHP-Encryption requires a key object instead of a string.
+      $key = Encoding::saveBytesToChecksummedAsciiSafeString(Key::KEY_CURRENT_VERSION, $key);
+      $key = Key::loadFromAsciiSafeString($key);
       return Crypto::decrypt($text, $key);
     }
-    catch (Ex\CryptoTestFailed $ex) {
-      return FALSE;
-    }
-    catch (Ex\CannotPerformOperation $ex) {
+    catch (Ex\CryptoException $ex) {
       return FALSE;
     }
   }
