예제 #1
1
 /**
  * Decrypt a string
  * 
  * @param string $encoded
  * @return string
  */
 public function decrypt($encoded)
 {
     $decoded = \base64_decode($encoded);
     \Sodium::memzero($encoded);
     $nonce = \mb_substr($decoded, 0, \Sodium::CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
     $ciphertext = \mb_substr($decoded, \Sodium::CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
     $decrypted = \Sodium::crypto_secretbox_open($ciphertext, $nonce, $this->key->getKey());
     \Sodium::memzero($decoded);
     \Sodium::memzero($nonce);
     \Sodium::memzero($ciphertext);
     return $decrypted;
 }