0 votes
in VBA by Expert (892 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");

			byte[] mb = md.digest();
			String out = "";
			for (int i = 0; i < mb.length; i++) {
				byte temp = mb[i];
				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 Skilled (749 points)
by Expert (892 points)
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
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.


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