Creating SHA Encrypted Values

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6965
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Creating SHA Encrypted Values

Post by FourthWorld » Sat Mar 11, 2017 12:21 am

mickpitkin92 wrote:I'm looking forward to seeing the messageDigest function get updated, hopefully it will have some clear documentation to help users figure out the correct syntax to generate say a SHA3 hash or other hash types.
The syntax noted in the pull request I linked to seems pretty straightforward for all types:

Code: Select all

messageDigest(<type>, <message>) 
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

sphere
Posts: 957
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Creating SHA Encrypted Values

Post by sphere » Fri Mar 31, 2017 1:19 pm

Very nice.
I'm just stepping into this encryption bussiness.

I want to change a program whcih stores now plain text to a database. But it's better to change some sensitive data into encrypted data.
My idea was : encrypt--->Base64 encode--->store into database (base64 so it becomes a string instead of binarydata, so no hassle with trailing zeros as i have read here and there)
then Read again for DB -->Base64 decode--->decrypt

Have to test some things
2018 Worldwide Mobile Market share: Android 84.4% !!!, iOs 15.1%, others 0.1%

sphere
Posts: 957
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Creating SHA Encrypted Values

Post by sphere » Thu Jun 15, 2017 9:03 pm

lc9 dp7 new sha released today :D
2018 Worldwide Mobile Market share: Android 84.4% !!!, iOs 15.1%, others 0.1%

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 230
Joined: Tue Jun 30, 2009 11:15 pm

Re: Creating SHA Encrypted Values

Post by mickpitkin92 » Sun Nov 10, 2019 2:29 am

So looking at the MessageDigest function, it does indeed spit out a digest of the data, but I was wondering how I would go about converting that into the alphanumeric string that you would get from Mark Smith's library or PHP.

For example, if I put Hello World into an online SHA256 generator, I get the string "A591A6D40BF420404A011733CFB7B190D62C65BF0BCDA32B57B277D9AD9F146E" and I honestly cannot remember how to convert a digest to the necessary string. It used to be in the dictionary for MD5Digest but has been taken out now.

Mike

bogs
Posts: 3939
Joined: Sat Feb 25, 2017 10:45 pm

Re: Creating SHA Encrypted Values

Post by bogs » Sun Nov 10, 2019 2:42 am

Max's wiki still has it. I often find the wiki faster than the current dictionary and in many cases, it has additional information added for the entries (in this case, 2 comments go much further into it :D ).
Last edited by bogs on Sun Nov 10, 2019 2:43 am, edited 1 time in total.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6965
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Creating SHA Encrypted Values

Post by FourthWorld » Sun Nov 10, 2019 2:42 am

LC returns the raw binary form of values returned from hashes, but you can transform binary data into hex with the binaryDecode function:

Code: Select all

on mouseup
   put HexHash("Hello World", "sha-256")
end mouseup

function HexHash pStr, pHashMethod
   put messageDigest(pStr, pHashMethod) into tmp
   get binaryDecode("H*", tmp, tHex)
   return tHex
end HexHash
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Databases”