0 votes
in VBA by Skilled (605 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 "";
	}

}

 

Please log in or register to answer this question.

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
Register
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.

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:

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.

Register

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

...