Quantcast
Channel: Micro Focus Forums
Viewing all articles
Browse latest Browse all 11924

Java code to JavaScript or Options?

$
0
0
Hi all,

I am trying to implement code where I take a password then encode the password with SHA512 and a Salt.

I have developed the Java code, and tested it in Eclipse and everything is working swell!

Now I am trying to get this function into IDM so I can call it from a Driver and it will return the Salt and the Digest.

Here is the code:
Code:

import java.io.UnsupportedEncodingException;
import java.security.*;


public class SHA512Salt {

        private static StringBuffer getHash(String saltPass) throws NoSuchAlgorithmException, UnsupportedEncodingException {
                        MessageDigest md = MessageDigest.getInstance("SHA-512");
                        md.update(saltPass.getBytes());
                       
                        byte byteData[] = md.digest();
                       
                //convert the byte to hex format method 1
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
                }
              return sb;
        }
       
        private static String getRandomSalt() {
                        SecureRandom random = new SecureRandom();
                        long challange = random.nextLong();
                        String SaltRDM = Long.toHexString(challange).toLowerCase();
                        return SaltRDM;
        }
       
        public static String encPassword(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
                String rdmSalt = getRandomSalt();
                String saltPass = rdmSalt.concat(password);
                StringBuffer digest = getHash(saltPass);
                return "SALTED"+rdmSalt+digest;
               
        }
}

How can I get this into Desginer now? Do I need to convert it to JavaScript??

Viewing all articles
Browse latest Browse all 11924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>