Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6954871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:39:48+00:00 2026-05-27T14:39:48+00:00

I need to convert this java code in force.com apex. i tried to use

  • 0

I need to convert this java code in force.com apex. i tried to use Crypto class to get same encryption but not getting how can i get same value for the variable “fingerprintHash” in the last in APEX . Can Anyone help me in this technical issue?

Random generator = new Random();
sequence =Long.parseLong(sequence+""+generator.nextInt(1000));

timeStamp = System.currentTimeMillis() / 1000;

try {
    SecretKey key = new SecretKeySpec(transactionKey.getBytes(), "HmacMD5"); 
    Mac mac = Mac.getInstance("HmacMD5");
    mac.init(key);

    String inputstring = loginID + "^" + sequence + "^" + timeStamp + "^" + amount + "^";
    byte[] result = mac.doFinal(inputstring.getBytes());

    StringBuffer strbuf = new StringBuffer(result.length * 2);

    for (int i = 0; i < result.length; i++) {
        if (((int) result[i] & 0xff) < 0x10) {
            strbuf.append("0");
        }

        strbuf.append(Long.toString((int) result[i] & 0xff, 16));
    }

    fingerprintHash = strbuf.toString(); //need this result for variable x_fp_hash 

The apex code I was trying is :-

String API_Login_Id='6########';
String TXn_Key='6###############';
String amount='55';
sequence = '300';

long timeStamp = System.currentTimeMillis()/1000;

String inputStr = API_Login_Id + '^' + sequence + '^' + timeStamp + '^' + amount + '^';
String algorithmName = 'hmacMD5';

Blob mac = Crypto.generateMac(algorithmName,Blob.valueOf(inputStr),Blob.valueOf( TXn_Key));
String macUrl =EncodingUtil.urlEncode(EncodingUtil.base64Encode(mac), 'UTF-8');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:39:49+00:00Added an answer on May 27, 2026 at 2:39 pm

    The problem would seem to be that you are hex encoding the output on the javaside, but base64 encoding the output on the apex side, try using EncodingUtils.convertToHex instead of EncodingUtils.base64Encode

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert the code snippet given in this http://www.movable-type.co.uk/scripts/latlong.html into java.
That sounds pretty odd but i have this cod and i need to convert
I need to convert a Word document into HTML file(s) in Java. The function
I am porting some stuff from C# to Java and I need a class
I need to convert a country code to a currency in my app on
How do I convert a unsigned char buffer to a jbyteArray? I need get
For GWT client side you need Java source code so i got that idea
i want to convert an avi file to 3gp using java program. For this
I am trying to convert a piece of Java code which uses a HashMap
I am having this encoding issue in java, one string I actually need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.