예제 #1
0
 /**
  * Encrypt a string
  * 
  * @param string $plaintext
  * @return string
  */
 public function encrypt($plaintext)
 {
     $nonce = \Sodium::randombytes_buf(\Sodium::CRYPTO_SECRETBOX_NONCEBYTES);
     $encrypted = \base64_encode($nonce . \Sodium::crypto_secretbox(\json_encode($plaintext), $nonce, $this->key->getKey()));
     \Sodium::memzero($plaintext);
     return $encrypted;
 }