Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public String descriptPassword(String str) {
        try {
            byte[] digest = MessageDigest.getInstance("SHA-256").digest(str.getBytes("UTF-8"));
            StringBuffer stringBuffer = new StringBuffer();
            for (byte b : digest) {
                String hexString = Integer.toHexString(b & 255);
                while (hexString.length() < 2) {
                    hexString = "0" + hexString;
                }
                stringBuffer.append(hexString);
            }
            return stringBuffer.toString();
        } catch (Exception e) {
            return e.toString();
        }
    }


What I have tried:

How to convert code from JAVA TO PHP
Posted
Updated 10-Mar-22 6:22am

There is no automatic way to do it. You can find tools like this[^] and get most of it in place but then you have to spend time to make sure all is right and close on the loose ends. This would mean you need to have basic understanding of both the languages so that you can confidently convert it.

You can always post specific query when you are trying to convert and get help. Attempt and see where you get stuck.
 
Share this answer
 
This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be “good code” in the target language – they are based on very different frameworks, and what makes something work in one language does not always “translate” directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can't be upgraded nicely, and that will cause you immense headaches if the original is changed. And it'll be a nightmare to debug if it doesn't work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it w=from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.
 
Share this answer
 
No conversion is necessary, PHP contains built in support: PHP: Password Hashing - Manual[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900