How to decode and encrypted value using DESEDE and a .key file?

Explorer ,
Apr 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

Hi all. Help would be very appreciated...

 

I have a requirement to accept a POST parameter that is encrypted using DESede/ECB/PKCS5Padding, and decrypt that param for use in my application. 

 

In attempting to test out this encryption and decryption, the following code was found to work successfully:

<cfset theKey = generateSecretKey('DESEDE')>
<cfset varString = "Testing">
<cfset encrypted=encrypt(varString, theKey, 'DESEDE','Base64')> 
<cfset decrypted=decrypt(encrypted, theKey, 'DESEDE','Base64')>
<cfdump var="#decrypted#">

 

Our issue is that in the test above the key value produced appears to be plain text, but the key that we are receiving from our data sender is in a .key file, and which seems to contain binary data. Can anyone tell me how a .key file might be used to decrypt a desede encrypted file?

TOPICS
Advanced techniques

Views

85

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Explorer , Apr 29, 2021 Apr 29, 2021
Thank you for the effort, BKBK, but what worked was running the binary data through the ToBase64() function.

Likes

Translate

Translate
Adobe Community Professional ,
Apr 26, 2021 Apr 26, 2021

Copy link to clipboard

Copied

Without much thought, my immediate instinct is to try something like:

<!--- First check whether the key file contains comments. If so, you might have to filter them out before going any further. --->
<cffile action="readbinary" file="absolute_path_to_key_file" variable="keyAsBinary">
<cfset theKey = toString(keyAsBinary)>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Thank you for the effort, BKBK, but what worked was running the binary data through the ToBase64() function.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

Glad to hear. Could you please share your code? It will help someone else in future, of that I am sure.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

LATEST

Thsi is the code that worked:

<cffile action="readbinary" file="C:\junk\myBinaryKey.key" variable="keyAsBinary">
<cfset myKey = ToBase64(keyAsBinary)>
<cfoutput>#myKey#</cfoutput>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines