doutuo7126 2013-04-03 05:19
浏览 154
已采纳

这种Java加密方法的等效PHP解密是什么?

I have the following Java encryption method, and I'd like to know what the equivalent PHP decryption for it is, if there is one. If there is not an equivalent PHP decryption function for PHP, then what other options do I have? Thanks in advance.

    private String encrypt(String string, String key) {
    StringBuilder enc = new StringBuilder();
    try {
        Mac mac = Mac.getInstance("HMACSHA256");
        SecretKeySpec secret = new SecretKeySpec(key.getBytes(), "HMACSHA256");
        mac.init(secret);
        byte[] digest = mac.doFinal(string.getBytes());
        for (byte b : digest) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1)
                enc.append('0');
            enc.append(hex);
        }
    } catch (Exception e) {
    }
    return enc.toString();
}
  • 写回答

2条回答 默认 最新

  • dqh19413 2013-04-03 05:37
    关注

    Just take a look at php.net: http://www.php.net/manual/en/function.hash-hmac.php

    An equal method would be

    hash_hmac("sha256", $data, $key, false);
    

    And of course its not an encryption, but an hash function. So its non reversible.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?