Thanks for the reply,
CryptDecrypt( CryptEncrypt( CryptAuthCode ( $DATA ; "SHA256" ; "9cfb29377943159b41c06df5296cc694795f0e2dedd6a89440efc59727ccc236" ) ; "whishthiswouldwork" ) ; "whishthiswouldwork" )
I presume hmac.data is a file and what lies within looks something like this
is that correct???
if so any ideas how i can get it?
2 of 2 people found this helpful
You need to perform them as separate actions, rather than trying to do it all in one calculation.
CryptEncrypt() results in a container file, so use Set Field to stick that into a container. Then use CryptDecrypt() to test decrypting that container’s file.
Read the documentation I linked to, it is much more thorough and there are other functions you may be able to use as well.
Set Field container with CryptEncrypt( CryptAuthCode ( $DATA ; "SHA256" ; "9cfb29377943159b41c06df5296cc694795f0e2dedd6a89440efc59727ccc236" ) ; "whishthiswouldwork" )
Container field contents are
set variable $HMAC1 using CryptDecrypt( Subscriptions::Container ; "whishthiswouldwork" )
so the encrypt, decrypt appears to be working but still returns the original file/container
Why are you double encrypting your data with:
CryptEncrypt( CryptAuthCode ( $DATA ; "SHA256" ; "9cfb29377943159b41c06df5296cc694795f0e2dedd6a89440efc59727ccc236" ) ; "whishthiswouldwork" )
Did you try just:
CryptEncrypt( "9cfb29377943159b41c06df5296cc694795f0e2dedd6a89440efc59727ccc236" ; "whishthiswouldwork" )
You are basically encrypting an encrypted file, then only decrypting it one step. This results in an encrypted file (your hmac.data), that still requires an additional level of decryption from you using CryptAuthCode()
Example 1 on your linked help file shows the operations in one step:
Returns This needs protection, the text that was encrypted using CryptEncrypt with the same key.
CryptEncrypt ( "This needs protection" ; "My secret password" ) ;
"My secret password"
I also struggled with CryptAuthCode when it became available. I was able to get the BaseElements plugin to work, but not the native function.
1. CryptAuthCode in 16.0.1 does not produce correct results.
2. CryptAuthCode works internally with binary data.
What does this mean? Firstly you need to be running at least 16.0.2. Secondly whereas the BaseElements plugin allows you to specify if C and K are Hex or Base64 you need to encode C and K appropriately for it to produce same results. If you just pass in a Hex string it will be treated as text ... not what you intended.
Try something like this;
Lower ( HexEncode ( CryptAuthCode ( C ; "SHA1" ; K ) ) )
C = HexDecode ( Globals::Data ; "data.bin" )
K = HexDecode ( Globals::Key; "key.bin")
The Data and Key fields contain Hex strings.