0 votes
in VBA by Expert (916 points)

Hello everyone

I have searched for a way to encrypt the string to SHA512 With SALTED String

I found a code for JAVA but not for VBA. Can you help me converting this JAVA script to VBA?

package javaTests;

import java.security.*;

public class EncryptTest {

	public static void main(String[] args) throws NoSuchAlgorithmException {
		System.out.println(getSHA512("123", "AAZZ"));
	}

	public static String getSHA512(String toHash, String salt) {
		for (int i = 0; i < 100000; i++) {
			toHash = SHA512once(toHash + salt);
		}
		return SHA512once(toHash);
	}

	private static String SHA512once(String toHash) {

		MessageDigest md;
		String message = toHash;
		try {
			md = MessageDigest.getInstance("SHA-512");

			md.update(message.getBytes());
			byte[] mb = md.digest();
			String out = "";
			for (int i = 0; i < mb.length; i++) {
				byte temp = mb[i];
				@SuppressWarnings("deprecation")
				String s = Integer.toHexString(new Byte(temp));
				while (s.length() < 2) {
					s = "0" + s;
				}
				s = s.substring(s.length() - 2);
				out += s;
			}
			return (out);

		} catch (NoSuchAlgorithmException e) {
			System.out.println("Error: " + e.getMessage());
		}
		return "Error";
	}

	public static String salt(String toSalt, String salt) {
		return "";
	}

}

 

1 Answer

0 votes
by Expert (911 points)
by Expert (916 points)
+1
Thanks a lot. I already got an answer but if you looked at comments, you will find that I have said the output is different not the same as in Java.

Welcome to wellsr Q&A
Ask any questions you have about VBA and Python and our community will help answer them. wellsr Q&A is the standalone question and answer platform for wellsr.com. If you have a question about one of our specific tutorials, please include a link back to the tutorial.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Looking for something else? Hire our team directly through ourVBA Help page, instead.

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...