I have no experience with C# and was wondering if someone can help converting this C# snippet into ColdFusion.
string inputString = "abccde";
string securityKey = "abcdefghijk...";
// Convert security key into ASCII bytes using utf8 encoding
byte[] securityKeyBytes = UTF8Encoding.ASCII.GetBytes(securityKey);
// Create an HMACSHA1 hashing object that has been seeded with the security key bytes
HMACSHA1 hasher = new HMACSHA1(securityKeyBytes);
// Convert input string into ASCII bytes using utf8 encoding
byte[] inputBytes = UTF8Encoding.ASCII.GetBytes(inputString.ToCharArray());
// Compute the has value
byte[] hash = hasher.ComputeHash(inputBytes);
// Convert back to a base 64 string
string securityToken = Convert.ToBase64String(hash);
return securityToken;
I found this on stackOverFlow and here what I have so far. I'm I going in the right direction? Any insights would be much appreciated!
<cffunction name="CFHMAC" output="false" returntype="string">
<cfargument name="signMsg" type="string" required="true" />
<cfargument name="signKey" type="string" required="true" />
<cfset var key = createObject("java", "javax.crypto.spec.SecretKeySpec").init(signKey.getBytes(), "HmacSHA1") />
<cfset var mac = createObject("java", "javax.crypto.Mac").getInstance("HmacSHA1") />
<cfset mac.init(key) />
<cfreturn toBase64(mac.doFinal(signMsg.getBytes())) />
</cffunction>
<cfset signMsg= "abccde">
<cfset signatureString = "abcdefghijk...">
<cfset result = CFHMAC(signMsg=signMsg, signKey=signatureString) />
<cfdump var="#result#" />