Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent PHP decryption for this Java encryption method?

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();
}
like image 382
Hat Avatar asked Sep 27 '26 23:09

Hat


1 Answers

SHA algorithms are one way hashes, which means you can never decrypt them.

like image 195
Pradeep Pati Avatar answered Sep 29 '26 13:09

Pradeep Pati