From 0eafef49dc1dbf72c405683156b94a8b109c8d87 Mon Sep 17 00:00:00 2001 From: varshith264 <67782495+varshith264@users.noreply.github.com> Date: Sat, 5 Oct 2024 11:34:10 +0530 Subject: [PATCH] add utility to compute appHashId using SHA256 of clientId and secretKey --- sample/App.java | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sample/App.java b/sample/App.java index 6d6c8ea..2678b3a 100644 --- a/sample/App.java +++ b/sample/App.java @@ -25,7 +25,7 @@ public class App implements FyersSocketDelegate { public static void main(String[] args) { String clientID = ""; String secretKey = ""; - String appHashId = ""; + String appHashId = getSHA256Hash(clientID, secretKey); String redirectURI = "https://trade.fyers.in/api-login/redirect-uri/index.html"; String code = ""; @@ -458,6 +458,25 @@ public void GetOptionChain(FyersClass fyersClass) { } + public String getSHA256Hash(String clientId, String secretKey) { + String input = String.format("%s:%s", clientId, secretKey); + try { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] encodedhash = digest.digest(input.getBytes()); + StringBuilder hexString = new StringBuilder(); + for (byte b : encodedhash) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + return hexString.toString(); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + public void WebSocket() { //Order Socket List list = new ArrayList<>(); @@ -572,4 +591,4 @@ public void OnMessage(JSONObject message) { System.out.println("OnMessage: " + message); } -} \ No newline at end of file +}