飞书小程序解密敏感数据

2022-07-08 09:51:01 +08:00
 laravel

https://open.feishu.cn/document/uYjL24iN/ugjMx4COyEjL4ITM

示例中没有 php 语言,看来 php 是真的不重视了,上次集成 google firebase 也是,官方没提供 php 支持。

    if ($user) {
      $aesKey = base64_decode($user->sessionKey);
      $aesIV = base64_decode($iv);

      $aesCipher = base64_decode($encryptedData);
      $result = openssl_decrypt( $aesCipher, 'AES-128-CBC', $aesKey, 1, $aesIV );
      info( json_encode($result) );
      info( openssl_error_string() );
      /*$user->update([
        'avatarUrl' => $avatarUrl,
        'nickName' => $nickName,
      ]);*/
    }

报错

local.ERROR: openssl_decrypt(): IV passed is 24 bytes long which is longer than the 16 expected by selected cipher, truncating {"exception":"[object] (ErrorException(code: 0): openssl_decrypt(): IV passed is 24 bytes long which is longer than the 16 expected by selected cipher
792 次点击
所在节点    程序员
3 条回复
rekulas
2022-07-08 09:58:34 +08:00
iv = 'f210af090c830cd5c47e67eeb4f52001';
错误很明显,iv 是 hex 你用 base64 解码那肯定错的 hex2bin
laravel
2022-07-08 09:59:02 +08:00
让我改好了

```
$aesKey = hex2bin($user->sessionKey);
$aesIV = hex2bin($iv);
```

但是又报

error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length

这个应该好解决了
laravel
2022-07-08 09:59:27 +08:00
@rekulas 是啊,就是这里的问题,谢谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/864832

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX