Hi all still having bother trying to convert an image to Binary, encrypt it and then decrypt it and convert back from binary 64 to display the image. I think I have made some progress. Not getting errors but the image is displaying as a broken image once its been decrypted and converted back from Binary.
Can anyone tell me what I am missing here? Tearing my hair out - any help would be so much appreciated 🙏
I have created a simple form which submits to a page to out put the results.
THE FORM
<form action="coldfusionencryption.cfm" method="post" enctype='multipart/form-data'>
<p>Input your key:</p>
<p><input type="text" name="myKey" value="foobar"><p>
<p>Input your string to be encrypted: <input type="file" name="myString"></p>
<p><input type="Submit" value="submit"></p>
</form>
THE ACTION PAGE AND OUTPUT
<CFIF IsDefined("form.myString")>
<CFSCRIPT>
string = ToBase64(Form.myString);
key = FORM.myKey;
encrypted = encrypt(string, key);
decrypted = decrypt(encrypted, key);
strNewValue = ToString( ToBinary( decrypted ) )
hashed = hash(string);
</cfscript>
<CFOUTPUT>
<H4><B>The string:</B></H4> #string# <BR>
<H4><B>The string's length:</B></H4> #len(string)# <BR>
<H4><B>The key:</B></H4> #key#<BR>
<H4><B>Encrypted:</B></H4> #encrypted#<BR>
<H4><B>The encrypted string's length:</B></H4> #len(encrypted)# <BR>
<H4><B>Hashed:</B></H4> #hashed#<BR>
<H4><B>The hashed string's length:</B></H4> #len(hashed)# <BR>
<H4><B>The decrypted string's </B></H4> #decrypted# <BR>
<img src="data:image/png;base64, #strNewValue#">
</CFOUTPUT>
</CFIF>
THE HTML PAGE OUTPUT