Skip to main content
Participant
November 17, 2009
Question

Encryption Problem

  • November 17, 2009
  • 1 reply
  • 442 views

Hi,

if i try to encrypt a String like "ABCDEFGHIJKLMN"
with the key like "mykey" then
i get a different signature to the php encryption with the same
Strings.

PHP Syntax:
------------------------

$myHash = 'ABCDEFGHIJKLMN';
$myKey = 'mykey';
echo base64_encode(hash_hmac('sha1', $myHash, $myKey, true));



CF Syntax:
------------------------

cfset baseString = 'ABCDEFGHIJKLMN'
cfset key = 'mykey'

cfset secret = createObject("java", "javax.crypto.spec.SecretKeySpec" )
cfset secret.init(baseString.GetBytes(), "HmacSHA1")

cfset mac = createObject( "java", "javax.crypto.Mac" )
cfset mac = mac.getInstance("HmacSHA1")
cfset mac.init(secret)

cfset encoder = createObject( "java", "sun.misc.BASE64Encoder" )
cfset digest = encoder.encode(mac.doFinal(key.GetBytes()))
cfset digest = toString(digest)
cfoutput#digest#/cfoutput

Funny part is, if i set the basestring and the key to "TEST"
i get same results in PHP and CF

Hope you guys can help me 😕😕

Greetings

Simon

    This topic has been closed for replies.

    1 reply

    Inspiring
    November 17, 2009

    Hi,

    I ran across a similar problem a while ago. We had CF generate an encrypted string to validate in ASP and could not get it to match. As it turned out, the cases used in the generated string were different and ASP could not match that. I had to Upper case the CF generated string to make it work.

    You might ran into the same problem!

    Good luck.

    sircromAuthor
    Participant
    November 18, 2009

    Hi Bert,

    thanks for answer. But this didnt solved my problem.

    But i have solved the problem by a simple switch of the

    baseString and the key in my Script.

    Newbie Fault :-)

    Greetings

    Simon