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 8841381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:42:11+00:00 2026-06-14T10:42:11+00:00

Trying to convert C# code to CF and im stuck translating the following line

  • 0

Trying to convert C# code to CF and im stuck translating the following line

StorageKey = 'abcd';
Convert.FromBase64String(StorageKey)

The above line produces a byte array of 105,183,29

The line is taken from Azure’s creating authorisation header;

System.Security.Cryptography.HMACSHA256 SHA256 = new System.Security.Cryptography.HMACSHA256(Convert.FromBase64String(StorageKey));

I’ve looked up FromBase64String Method on msdn library but its over my head. I hope someone can point me in the right Coldfusion direction.

I’ve tried BinaryDecode(StorageKey,”BASE64″), to me that seemed the most logical translation but im getting back 105-7329 which is not my expected result.

See Leigh’s answer below for CF10+, if you are after a CF7-9 solution this my attempt

var javaMsg = javacast("string", arguments.sigMsg).getBytes("UTF-8");
var javaKey    = JavaCast("string", arguments.sigKey);
var myKey     = createObject('java', 'javax.crypto.spec.SecretKeySpec' );
var mac     = createObject('java', "javax.crypto.Mac");
var myKeyB64  = CreateObject("java", "org.apache.commons.codec.binary.Base64").decodeBase64(javaKey.getBytes());
var secret  = myKey.Init(myKeyB64, 'HmacSHA256');
mac         = mac.getInstance("HmacSHA256");
mac.init(secret);
</cfscript>
<cfdump var="#mac.doFinal(javaMsg)#">
  • 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-06-14T10:42:13+00:00Added an answer on June 14, 2026 at 10:42 am

    The line is taken from Azure’s creating authorisation header;

    mbeckish is correct about the sign differences between C# and CF/java. However, I do not think the internal representation should make any difference to your end result, which is usually all you care about. Normally you do not need to match the low level integer values, just the string representation of the bytes in base64 or hex. As long as you compare the final HMAC values in a common format, like base64, they should be exactly the same.

    For example, if you take the sample signature string here, both CF10 and C# return the same value. So it seems likely your problem is something else.

    <cfscript>
        savecontent variable="signatureString" {
            WriteOutput("GET#chr(10)##chr(10)##chr(10)##chr(10)#x-ms-date:Mon, 01 Dec 2008 05:17:57 GMT#chr(10)#/accountname/queuename/messages");
        };
        key = binaryDecode("abcd", "base64");
        resultInHex = hmac(signatureString, key,"HMACSHA256");
        // result: wxR7Bt6sWEKVJ9vEjCiuqA8OKCZOKYfbxaXj85whOkM=
        WriteDump(binaryEncode(binaryDecode(resultInHex, "hex"), "base64"));
    </cfscript>
    

    EDIT: I know there are a bunch of pre-CF10 hmac functions floating around. But many of them forget about encoding. Here is a generic adaptation that accepts an algorithm (“hmacsha256”, “hmacsha1”, ..) and encoding (“utf-8”). It should work with CF7-9.

    <cfset result = hmacX( signatureString, "abcd", "HmacSHA256") />
    <cfdump var="#result#" />
    
    <cffunction name="hmacX" returntype="string" hint="">
        <cfargument name="message" type="string" required="true" />
        <cfargument name="keyInBase64" type="any" required="true" />
        <cfargument name="algorithm" type="string" default="HmacSHA256" />
        <cfargument name="encoding" type="string" default="UTF-8" />
    
        <cfset var dataBytes  = charsetDecode( arguments.message, arguments.encoding ) />
        <cfset var keyBytes  = binaryDecode( arguments.keyInBase64, "base64" ) />
        <cfset var keySpec = createObject("java", "javax.crypto.spec.SecretKeySpec") />
        <cfset var secret = keySpec.init( keyBytes, arguments.algorithm ) />
        <cfset var mac  = createObject("java", "javax.crypto.Mac").getInstance( arguments.algorithm ) />
    
        <cfset mac.init( secret ) />
    
        <cfreturn binaryEncode( mac.doFinal(dataBytes), "base64") />
    </cffunction>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert code from Delphi to .Net. I'm stuck on one line:
I am trying to convert the following code from Trefethen's Spectral Methods in MATLAB
I m trying to convert the following code to another AJAX call, in order
I am trying to convert the following code for the variance calculation public static
I'm trying to convert the following bash code into C++ using boost::iostreams: #!/usr/bin/bash (
I'm trying to convert this code fragment into Delphi and I got stuck on
i'm trying to convert code from c++ to c#.. but i'm stuck. Can somebody
Im trying to retrieve a query as a byte array. Im stuck @ the
I am stuck trying to debug some code that is designed to convert an
I'm trying to convert some code from Richfaces 4 showcase to use CDI instead

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.