Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Javascript code to ABAP for calculating HMAC

Sourav1
Participant
533

Hi,
I am trying to generate a SAS Token from ABAP to connect to Azure Service Bus as described in the following link
https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token#using-the-shared-access-signat...

I want to convert the below code to ABAP. Kindly, help out.
The Javascript Code is as follows:

  function createSharedAccessToken(uri, saName, saKey) { 
    if (!uri || !saName || !saKey) { 
            throw"Missing required parameter"; 
        } 
    var encoded = encodeURIComponent(uri); 
    var now = newDate(); 
    var week = 60*60*24*7;
    var ttl = Math.round(now.getTime() / 1000) + week;
    var signature = encoded + '\n' + ttl; 
    var signatureUTF8 = utf8.encode(signature); 
    var hash = crypto.createHmac('sha256', saKey).update(signatureUTF8).digest('base64'); 
    return'SharedAccessSignature sr=' + encoded + '&sig=' +  
        encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName; 
}
1 ACCEPTED SOLUTION

larshp
Active Contributor
94

Guess this will work, https://github.com/Microsoft/ABAP-SDK-for-Azure/blob/7de07cdcf35e8ef60a292d1e6f845bfe3bc39394/src/za...


Its part of the Microsoft ABAP SDK for Azure, which you might want to consider using instead of developing it from scratch

1 REPLY 1

larshp
Active Contributor
95

Guess this will work, https://github.com/Microsoft/ABAP-SDK-for-Azure/blob/7de07cdcf35e8ef60a292d1e6f845bfe3bc39394/src/za...


Its part of the Microsoft ABAP SDK for Azure, which you might want to consider using instead of developing it from scratch