我有一个MYSQL数据库,用于存储IMAP帐户的加密凭据。 密码字段是推荐的BLOB。
$encrypter = new TripleDES(CRYPT_DES_MODE_ECB);
$encrypter->setKey($this->container->getParameter('secure_token'));
$encrytped_pw = $encrypter->encrypt("MYPASSWORD");
$mailbox->setUrl('{outlook.office365.com:993/imap/ssl}');
$mailbox->setUsername('user@domain.tld');
$mailbox->setPassword(base64_decode($encrytped_pw));
$em->persist($mailbox);
$em->flush();
不幸的是我无法使用此解密此字段:
$mailboxPw = $this->getUser()->getMailbox()->getPassword();
$decrypter = new TripleDES(CRYPT_DES_MODE_ECB);
$decrypter->setKey($this->container->getParameter('secure_token'));
$decrytped_pw = $decrypter->decrypt(base64_encode($mailboxPw));
因为它给了我
Warning: base64_encode() expects parameter 1 to be string, resource given
我找不到将blob资源转换为字符串的方法,有没有其他方法可以实现我想要的呢?
任何暗示赞赏
答案 0 :(得分:0)
可以使用 stream_get_contents 来读取资源:
$mailboxPwResource = $this->getUser()->getMailbox()->getPassword();
$mailboxPw = stream_get_contents($mailboxPwResource);
$decrypter = new TripleDES(CRYPT_DES_MODE_ECB);
$decrypter->setKey($this->container->getParameter('secure_token'));
$decrytped_pw = $decrypter->decrypt(base64_encode($mailboxPw));