Hi all still having bother trying to convert an im...
# cfml-general
m
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
e
Set the Encryption Type, such as RSA or SHA1, 2, Encryption keyLength. See https://cfdocs.org/encrypt
p
@mauzer This code does not appear to be uploading the file, you are just attempting to just convert the form field value
form.theString
into a base64; thats just a temp string, not a file to handle your base64 encrypting etc.
s
you will need to do a fileUpload, and then a fileRead to get the actual data of the file
☝🏻 1
☝️ 1
here is a working version of your code, with an image https://trycf.com/gist/5be1185305786d9f28586d1465e90cec/lucee5?theme=monokai
m
@Scott Steinbeck fabulous! Ah I was trying to avoid uploading a file to the server and just store it and retrieve it as binary
Great 👍 really appreciate it thanks @Scott Steinbeck 🙏