Group: User Level: Neuling
Posts: 1 Joined: 6/20/2022 IP-Address: saved
| Trust this makes a difference:
import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Base64;
public class Test1 {
confidential static last String HMAC_SHA512 = "HmacSHA512";
public static void main(String[] args) { Macintosh sha512Hmac; String result; last String key = "Welcome1";
attempt { last byte[] byteKey = key.getBytes(StandardCharsets.UTF_8); sha512Hmac = Mac.getInstance(HMAC_SHA512); SecretKeySpec keySpec = new SecretKeySpec(byteKey, HMAC_SHA512); sha512Hmac.init(keySpec); byte[] macData = sha512Hmac.doFinal("My message".getBytes(StandardCharsets.UTF_8));
// Can either base64 encode or put it directly into hex result = Base64.getEncoder().encodeToString(macData); //result = bytesToHex(macData); } get (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { e.printStackTrace(); } at long last { // Put any cleanup here System.out.println("Done"); } } }
Java Classes in Pune
|