Is there a way to encrypt and encrypt images in CF...
# cfml-general
m
Is there a way to encrypt and encrypt images in CF ?
p
Could convert the image to base64 and then encrypt that string?
or just encrypt the byte array;
fileReadBinary()
🙏 1
p
👍🏻
🙏 1
a
TIL: expert-sexchange is still a thing
m
Nah link is broke 😂
p
Pretty basic if link doesnt explain what you need; just
filereadbinary()
and
encrypt()
should be pretty straightforward
🙏 1
m
@Patrick do these methods encrypt the image when in transit (when being uploaded ?) So for example someone wants to upload a sensitive document like a passport or drivers license, when they select their image or take a photo and upload it, what protects the image during that process? Sorry does that make sense 🤔
If its done via SSL I guess it should be ok but just a question I am being asked
d
SSL should do it, like the rest of the submit, yes?
m
@Dave Merrill thats my thinking yes
p
Yea SSL should do the trick, but adding the extra layer would be helpful; also when handling those types of info be sure you are in a PCI compliant environment and following best practices in handling PII
m
Awesome just needed to clarify that. Thanks @Patrick
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