How do I create SHA512 hash

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 240
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO
Contact:

How do I create SHA512 hash

Post by ctflatt » Fri Mar 03, 2017 3:31 am

Hello, everyone!

I have a current project that requires posting of an SHA512 hash of specified data to a particular web service. My question is not how the actual posting is done--I'm fine with that. What I do not know is how to create the SHA512 hash of the data.

I read another thread regarding this using libraries, but I have no idea how to use those libraries to achieve my hash out of Livecode.

If anyone could tell me where to start, generalize the process, or provide detailed instructions, I would be grateful.

Thank you for your help, and if you need more info, please let me know.

Christopher

SparkOut
Posts: 1643
Joined: Sun Sep 23, 2007 4:58 pm

Re: How do I create SHA512 hash

Post by SparkOut » Sun Mar 05, 2017 10:00 pm

I was going to suggest looking at the late Mark Smith's libhash-HMAC library http://marksmith.on-rev.com/revstuff/ but I see that caters for SHA256 but not SHA512. I don't know how complicated it would be to work through the SHA512 algorithm and either update or recode a SHA512 algo in LiveCode.
There is a helpful site here http://www.movable-type.co.uk/scripts/sha512.html with the SHA512 algorithm enabled in javascript, source code here cdn.rawgit.com/chrisveness/crypto/4e93a4d/sha512.js with some links to other more "production type" crypto libraries in javascript.
It might be possible to use a browser widget to leverage the javascript and return the hash. I would love to get into this a bit deeper but not likely to have a chance for a good while, but I hope this is at least better than a "nope, can't help" or stony silence.

(PS, Mark Smith's library needs a tweak or two to change/comment out a handler since sha1digest is now a reserved word in recent versions of LC.)

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 240
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO
Contact:

Re: How do I create SHA512 hash

Post by ctflatt » Tue Mar 07, 2017 2:31 am

SparkOut,

Thank you so much for taking the time to respond. I really do appreciate it.

Is it my correct understanding that iOS developers (and Android, for that matter?) have the ability to do this directly in the Xcode IDE (or whatever is being used for Android)?

I think I understand your mention of implementing the .js on a secure server (mine), but I don't think my savvy patron on this project would take kindly to sending out data to be hashed to be read back in. This project is like a "let's give Livecode a chance on a hardline production job..."

It's a simple app, I can create the strings to hash, i just can't implement an SHA512 directly from the IDE... a combined app bundle with library would be ideal but I am lost and he's looking for a status report tomorrow morning.

I may lose this one, which would be a shame, for my faith in Livecode...

Again, many thanks, and if you have more nuggets of wisdom for this... :)

Christopher

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

Re: How do I create SHA512 hash

Post by FourthWorld » Tue Mar 07, 2017 2:37 am

SHA2 and SHA3 are in development by the engine team right now, targeting inclusion in v9.
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/

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 240
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO
Contact:

Re: How do I create SHA512 hash

Post by ctflatt » Tue Mar 07, 2017 4:19 am

Thank you, Richard, for the reassurance. I do appreciate it!

SparkOut
Posts: 1643
Joined: Sun Sep 23, 2007 4:58 pm

Re: How do I create SHA512 hash

Post by SparkOut » Tue Mar 07, 2017 9:50 am

I meant above that it might be a possibility to use the javascript file as a local resource on the device and access it by leveraging a browser widget. I haven't had a chance to "paint-along", but I have seen a few threads discussing methods of communicating between browser scripts and livecode and I wondered if it might be possible to achieve the requirement that way.
If it is in development for native functionality, then that is great news.

ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 240
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO
Contact:

Re: How do I create SHA512 hash

Post by ctflatt » Tue Mar 07, 2017 4:01 pm

Many thanks to SparkOut and Richard for their help.

What I managed to find is this simple (for me) solution.

1) Create the string in Livecode to send to a php page hosted on my server. Example:

Code: Select all

put urlEncode(field "email") into tEmail
put urlEncode(field "password") into tPassword
put tEmail & ";" & tPassword into tArguments
post tArguments to url("http://yourserver/yourdirectory/yourphpfile.php?string=")
put it into tResult
answer tResult
then do with tResult what you need to do...

2) Create a simple-simple-simple php page with the following:

Code: Select all

<?php
$string = "hashString";//from posted LC string
echo hash ("sha512", $string);
?>
3) Because hashing is supported natively by PHP, I post the arguments from my Livecode fields to the url of the php page.

4) Once posted, the result is put into "it" to do with what I please.

This seems to work.

If anyone needs more info, let me know.

Great that this will be available from within Livecode in 9 (hopefully).

Thanks, again, SparkOut and Richard! I also want to thank Devin Assay for the invaluable info available from his BYU course resources.

I hope this helps anyone else looking for this functionality in a simple solution.

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

Re: How do I create SHA512 hash

Post by FourthWorld » Thu Mar 09, 2017 10:40 pm

FWIW there's been some great progress on a new messageDigest function for LiveCode Script which will support SHA2 and SHA3 in addition to MD5 and SHA1. It's in review now, and may be available as early as v9 DP7 - you can follow the progress on this at Github:
https://github.com/livecode/livecode/pull/5229
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: 480
Joined: Sat Sep 27, 2014 10:32 am
Location: the Netherlands

Re: How do I create SHA512 hash

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

released today lc9 dp7 with new SHA 2 and 3
Global Market Share WorldWide Android 84.82%
Global Market Share WorldWide iOs 12%

Just a wild guess that we need more support and features for Android than iOs...

ClipArtGuy
Posts: 90
Joined: Wed Aug 19, 2015 4:29 pm

Re: How do I create SHA512 hash

Post by ClipArtGuy » Wed Oct 11, 2017 6:46 pm

Is there any documentation on how to produce a SHA512 hash? I just did a search in the dictionary LC9 dp9, and the only function that pops up is sha1digest. Thanks!

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

Re: How do I create SHA512 hash

Post by FourthWorld » Wed Oct 11, 2017 7:15 pm

I believe you'll find the new hash options as param constants for the new messageDigest function.
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/

ClipArtGuy
Posts: 90
Joined: Wed Aug 19, 2015 4:29 pm

Re: How do I create SHA512 hash

Post by ClipArtGuy » Wed Oct 11, 2017 7:35 pm

FourthWorld wrote:
Wed Oct 11, 2017 7:15 pm
I believe you'll find the new hash options as param constants for the new messageDigest function.
Thanks Richard!

Post Reply

Return to “Databases”