V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laravel
V2EX  ›  程序员

飞书小程序解密敏感数据

  •  
  •   laravel · 2022-07-08 09:51:01 +08:00 · 787 次点击
    这是一个创建于 658 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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
    
    3 条回复
    rekulas
        1
    rekulas  
       2022-07-08 09:58:34 +08:00
    iv = 'f210af090c830cd5c47e67eeb4f52001';
    错误很明显,iv 是 hex 你用 base64 解码那肯定错的 hex2bin
    laravel
        2
    laravel  
    OP
       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
        3
    laravel  
    OP
       2022-07-08 09:59:27 +08:00
    @rekulas 是啊,就是这里的问题,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5359 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 08:34 · PVG 16:34 · LAX 01:34 · JFK 04:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.